CAB201 2024 S2 Practice Test Answers PDF

Summary

This document contains multiple-choice questions for a programming exam, likely for an undergraduate computer science course. It includes coding questions on subjects like data structures and algorithms, likely from a university like QUT.

Full Transcript

1 SECTION A Attempt all multiple-choice questions on the Test Answer Sheet. Each question is worth 1 mark. For each question, choose the best option that answers the question. QUESTION 1 (Week 1)...

1 SECTION A Attempt all multiple-choice questions on the Test Answer Sheet. Each question is worth 1 mark. For each question, choose the best option that answers the question. QUESTION 1 (Week 1) Commented [AW1]: a) An int represents whole numbers. b) The correct answer. A double represents floating point numbers. The literal value 3.14 will be stored in C# as which type? c) A string represents a series of Unicode characters with surrounding double quotation marks. (a) int d) A char represents a single Unicode character with surrounding single quotation marks. (b) double e) A bool represents true or false values. (c) string (d) char (e) bool QUESTION 2 (Week 1) Commented [AW2]: In C# identifiers must: ⦁ begin with a letter, an underscore character (_) or an at character (@) Which of the flowing is a valid identifier name: After the first character, they can only contain letters, digitsn and the underscore character. (a) Age ⦁ They cannot contain whitespace characters ⦁ They cannot use reserved words such as C# keywords (b) age without a @ prefix. (c) _age a), b), and c) are all valid identifiers, therefore d is the correct answer. (d) All of the above (e) None of the above QUESTION 3 (Week 2) Commented [AW3]: a)Default is used to execute a sequences of statements where the switch expressions are not matched to any of the case statements. It can also be used to In C# falling through a switch case is prevented by using the _____ statement. set the default of a parameter to a default value if no value is passed. (a) default b)A case represents is a value that the switch expression could match. (b) case c)The correct answer. This will stop the executing the current set of statements and exit the entire switch statement. (c) break Therefore, it stops the execution from falling through to the next set of matching case expressions. (d) end d)There is no keyword ‘end’ in C#. (e) None of the above QUESTION 4 (Week 3) Commented [AW4]: a)The correct answer. The body of the method is everything in the braces. b)c) d) are not called anything in C#. In C#, what is the body of a method? (a) Everything between the curly braces. (b) The parameter list and everything between the curly braces. (c) The method name, parameter list and everything between the curly braces (d) The return type, method name, parameter list and everything between the curly braces (e) None of the above CAB201 SAMPLE EXAM cont/… 2 QUESTION 5 (Week 3) Commented [AW5]: a)b), and c) all use an index to set or get items d) The correct answer. The dictionary uses a key-value pair to Which of the following collection uses a key-value pair? set/get items. Each key in the dictionary must be unique. (a) An array (b) A List (c) A List that is sorted (d) A Dictionary (e) None of the above QUESTION 6 (Week 5) Commented [AW6]: a)A method represents a behaviour, so it is not applicable to QUT. A class is a template applicable to a University. In object-oriented nomenclature, QUT is a(n) __________ and University is a(n) __________. b)A class is a template, so it is not applicable to QUT. An object is an instance, so it is not applicable to a University. (a) method, class c)A class is a template, so it is not applicable to QUT. A method represents a behaviour, so it is not applicable to a (b) class, object University. d)The correct answer. An object is an instance applicable to (c) class, method QUT. A class is a template applicable to a University. (d) object, class (e) None of the above QUESTION 7 (Week 5) Commented [AW7]: A default constructor: Is parameterless A default constructor: Sets all fields to default values (numbers to 0, booleans to false, characters to Unicode 0, strings to null, objects to null). (a) Sets numeric fields to 0 Sets visibility to public if the class is public (b) Is parameterless private if the class is private, protected if the class is abstract. (c) Sets string fields to null. Internal if the class is internal a)b) and c) align with the above, so the correct answer is d. (d) All of the above. (e) None of the above QUESTION 8 (Week 5) Commented [AW8]: e) is the correct answer. A method with a return type of void cannot return anything, which eliminates a), b), c), and d) as possible answers. In C#, a method with a return type of void: (a) Must contain a return statement (b) Returns an object with type void (c) Can only return null (d) Can return any type of object (e) None of the above CAB201 SAMPLE EXAM cont/… 3 QUESTION 9 (Week 5) Commented [AW9]: a)A method with the same return type, name, and parameter list in a single class will generate a compile-time error. In C#, correctly overloaded methods must have the same _______. b)The correct answer. A correctly written overloaded method needs the same name as another method but a different (a) Return type parameter list. c)For a method to be overloaded, it needs to have a different (b) Method name list of parameters than a method with the same name. (c) Parameter list (d) All of the above (e) None of the above QUESTION 10 (Week 6) Commented [AW10]: a)Nouns represent classes, fields, properties, parameters, and data. b) The correct answer. Verbs represent behaviours which are In object-oriented design, when trying to identify potential methods we look for what? usually implemented as methods. c)Adverbs tend not to be consider in object-oriented design (a) Nouns (maybe as an Enum?). d)Adjectives tend not to e considered in oriented-design (b) Verbs (maybe as an Enum?). (c) Adverbs (d) Adjectives (e) None of the above QUESTION 11 (Week 6) Commented [AW11]: a)There is no direct UML diagram to represent the user’s requitements but it is a user story. b)This is sequence diagram. What does a Class Diagram represent? c)The correct answer. d) This is a composite structure diagram. (a) The requirements of a user. (b) A temporal representation of the workflow at a particular time. (c) A static global view of the classes, fields, methods, properties and their relationships. (d) The internal structure of a class and the interactions between its parts. (e) None of the above QUESTION 12 (Week 6) Commented [AW12]: a)Fields are a single item or collection of items with an identifier and possible a value. This does not align with the unit coordinator. In the following user story: b)Methods are a single behaviour. They are mostly drawn from verbs in the user story, while a unit coordinator is a “As a unit coordinator, I want to create a unit with a code, name and number of students, so I noun. c)A property is a single item/collection of items with an can teach it.” identifier, with a possible value, and ways to set and get the item. The unit coordinator would likely be: d)The correct answer. The unit coordinator is a noun, so could be a class. It would also contain fields (unit) and behaviour/s (teaching) which are only applicable to classes. (a) A field. (b) A method. (c) A property. (d) A class. (e) None of the above CAB201 SAMPLE EXAM cont/… 4 QUESTION 13 (Week 7) Commented [AW13]: Overloading methods apply to a single class or the class's descendants. Specific types of objects assume features of more general classes through a)Polymorphism occurs when the same method name can (a) Polymorphism perform different actions. b)The correct answer. An aspect of inheritance means that a (b) Inheritance child class receives the features of a more general class. c)Encapsulation involves changing the internal (c) Encapsulation implementation within a method or class and protecting the internal parts of a class without affecting the external (d) Abstraction interface.. d)Abstraction involves examining the similarities between (e) None of the above different objects and providing an interface. QUESTION 14 (Week 7) Commented [AW14]: An overridden method applies to a parent-child inheritance relationship. An overridden method needs the following: In C#, correctly overridden methods must have the same _______. The parent class to have a method declared as virtual, (a) Return type abstract, or overridden The same name as a method in the parent class. (b) Method name The same return type as a method in the parent class. The same parameter list (the same number of parameters and (c) Parameter list corresponding types) as a method in the parent class. The same visibility as a method in the parent class. (d) All of the above a), b), and c) all satisfy some of the conditions above. (e) None of the above Therefore, d) is the correct answer. QUESTION 15 (Week 5 and 7) Commented [AW15]: a)Only accessible within the class where it was introduced. b)Accessible to all classes. In C#, what is the access level to use for members if you want them to be only accessible by c)The correct answer. Accessible to the class it was methods in the same class and any child classes introduced and its descendant classes. (a) private (b) public (c) protected (d) All of the above (e) None of the above QUESTION 16 (Week 8) Commented [AW16]: a. It is not possible to instantiate an object from either an abstract class or an interface. b. The correct answer. An abstract class can contain both Which of these is a difference between abstract classes and interfaces in C#? abstract and non-abstract methods. An interface can only contain abstract methods. (a) You can instantiate objects from an abstract class, but not an interface. c. It is not possible for a class to inherit from multiple classes (whether abstract or concrete). However, a class can (b) An abstract class can contain non-abstract methods, but an interface cannot. implement multiple interfaces. d. Methods can take either an abstract class or an interface (c) A class can inherit from multiple abstract classes, but not multiple interfaces. as a parameter. (d) Methods can take an abstract class as a parameter, but not an interface (e) None of the above CAB201 SAMPLE EXAM cont/… 5 QUESTION 17 (Week 8) Commented [AW17]: a) Abstraction is about examining the similarities between different objects and providing an interface. It does not implement behaviours. A bird, a plane, and a spaceship can all fly. This is an example of: b) Encapsulation involves changing the internal implementation within a method or class, protecting the (a) Abstraction internal parts of a class without affecting the external interface. (b) Encapsulation c) Inheritance means that a child class receives the features of a more general parent class. These three classes are (c) Inheritance unlikely to have the same parent class (except for Object). d) Polymorphism occurs when the same method name can (d) Polymorphism perform different actions. This is applicable to classes with different parent classes. (e) None of the above QUESTION 18 (Week 8) Commented [AW18]: a)An interface can only contain abstract methods and static fields and properties. b)Using an interface does not automatically mean that the What happens when calling a virtual method via an instance of an interface? base class would be called. It needs type casting or method hiding, with the child class using the ‘new’ keyword in the (a) It will cause a runtime exception because interfaces do not include implementations for method signature. c)An interface cannot decide on a class’s implementation. any methods This decision it in the class’s implementation. d)The correct answer. During execution the run-time type is (b) The method in the base class is invoked. used and implements its functionality. This covers a wider set (c) The interface delegates the method call to a class of its choosing. of possibilities and a more complete answer than answer b. (d) The run-time type of the object is used to determine which implementation of that method is invoked. (e) None of the above QUESTION 19 (Week 9) Commented [AW19]: a)The test will cause an error because the data is invalid and outside the suitable range. b)The correct answer. The lower limit is 1, and 0 is just For a QUT Unit to run during the semester requires that at least 1 student is enrolled. Writing a smaller that it. MSTest that creates a QUTUnit, sets its number of students to 0 and then calls the IsRunning c)The lower limit is 1, and 0 is not larger than it. method is an example of: d)The lower limit is 1, and is not equal to 0. (a) Valid testing. (b) Boundary testing just lower than the lower threshold. (c) Boundary testing just higher than the lower threshold. (d) Equals testing. (e) None of the above QUESTION 20 (Week 10) Commented [AW20]: a)This describes encapsulation. b)This describes type conversion. c)A child class can extend a parent class. Therefore, a parent The Liskov substitution principle requires that: class cannot be expected to be substituted for a child class since it will not have those extensions. d)The correct answer. A child class receives the features of a (a) The internal components of a class are protected. parent class. It can therefore be substituted for a parent class. (b) An integer argument can be substituted for a float argument in a method call. (c) An instance of a parent class can be used wherever an instance of its child class could be. (d) An instance of a child class can be used wherever an instance of its parent class could be. (e) None of the above END OF PAPER CAB201 Sample Exam

Use Quizgecko on...
Browser
Browser