Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 1 of 8

TEST 2
MULTIPLE CHOICE QUESTIONS
This section carries TWENTY FIVE (25) marks.
Each question carries ONE (1) mark. Answer ALL questions.

1. Which access modifier restricts the method access to the containing class and any derived
classes?

a) private
b) public
c) protected
d) static

2. In object oriented programming, every object ________?

a) is an attribute of another object


b) is an instance of a class
c) inherits from a class
d) has recursive methods

3. Select the C# keyword that is required in the class definitions to allow the code to compile
successfully?

public class Manager


{
public void EvaluateEmployee(Employee emp);
}
public class Manager
{
public void Login();
}

a) static
b) default
c) protected
d) partial

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 2 of 8

4. How do you enforce data hiding on your member variables?

a) Implement public members and public properties


b) Implement private members and private properties
c) Implement private members and public properties
d) Implement public members and private properties

5. Which of the below statements is true?

a) Inheritence models the IS-A relationship, in which the objects of the subclass are also objects
of the superclass.
b) The number of methods in a superclass is always higher than in each of its subclasses
c) Two subclasses of the same superclass always have the same number of methods
d) None of the above

6. You have created an abstract class and you want to force sub classes to implement a method.
How do you enforce this in C#?

a) Add the virtual keyword to the method


b) Declare the class as abstract
c) Add the abstract keyword to the method
d) Declare the class as virtual

7. Which of the below statements is true about a constructor method?

a) The return type void must be included in the declaration of a constructor.


b) A class can have several constructors.
c) Constructors need to receive at least one argument.
d) Constructors are special methods that can not be overloaded.

8. Consider the following method of C#:

private void ShowTax(decimal price, decimal taxRate = 0.07m)


{
decimal tax = price * taxRate;
}

The method ShowTax has been called using the following statement:
showTax (100.0m, 0.08m);

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 3 of 8

Which of the following is True for the above scenario?

a) Error in method call


b) Error in method body and statements
c) The default argument will override the argument provided in method call
d) The argument provided in method call will override the default argument

9. Given MyClass and YourClass classes, as shown below, what line should replace //...


[Here]... in YourClass?

public class MyClass {


private int a;
public MyClass (int a) {
this.a = a;
}
}
public class YourClass extends MyClass {
private int b;
public YourClass (int a, int b) //...[Here]... {

this.b = b;
}
}

a) MyClass(a)
b) base(a)
c) YourClass(a)
d) super(a)

10. Suppose that you want to develop a loyalty card scheme for an application related to a coffee
company. You might start by creating an interface for loyalty card holder that defines:

a) A read-only integer property named TotalPoints


b) A method named AddPoints that accepts a decimal argument
c) A method named ResetPoints
d) All of the above

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 4 of 8

11. Which of the following options is an example of overloading:

a) Two methods with the same name that are implemented in the same class, and that have the
same number and type of parameters
b) Two methods with the same name that are implemented in different classes, and that have the
same number and type of parameters
c) Two methods with the same name that are implemented in the same class, and that have the
same number of parameters but of different types
d) Two methods with the same name that are implemented in different classes, and that have the
same number of parameters but of different types

12. Which of the following statements is false?

a) A function is a block of code that performs a specific task


b) Functions allow programmers to break large and complex problems into small and
manageable tasks
c) Functions allow programmers to use existing code to perform common tasks.
d) Functions can be called, or invoked, only once in a program

13. A(n) _______________ is a method that is automatically executed when an object is created.

a. opener
b. loader
c. constructor
d. assembler

14. Consider the following code in C#:

class Rectangle
{
public Rectangle() {…}
public Rectangle(int length, int width)
{…}
}

class Box : Rectangle


{
private int _height;
public Box() { …. }
public Box(int length, int width, int height)
: base(length, width)

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 5 of 8

{ …. }
….
}

Which of the following statement is True about the code above?

a) base class parameterized constructor can be derived by base keyword in derived class
b) base class parameterized constructor is not inheritable
c) derived class cannot have parameterized constructor
d) None of the above

15. We note that the Employee class is being used as the base class for
Manager and Programmer. We can continue to extend the Employee class by creating as many
sub classes as required for different employees in our application. However, when looking at our
class hierarchy, it does not make sense to be able to create an object of which type directly?

a) Employee
b) Manager
c) Programmer
d) All of the above

16. Which of the following statements is Wrong about a List named myList?

a) List<string> myList = new List<string>();


b) myList.Add(“Chris”);
c) myList.Remove(“Joanne”);
d) List<string> myList = new List<int>() { 1, 2, 3 };

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 6 of 8

17. Consider the following C# code:

public string Name


{
get
{
return _name;
}
set
{
_name = value;
}
}
What is the purpose of above code?

a) To assign a value to _name property


b) To equalize _name and Name property
c) It defines a public property which cannot be used by others
d) It can make a private property accessible

18. Which of the following is not the property of Object Oriented Programming?

a) Inheritance
b) Classes and Objects
c) Function and Procedure
d) Polymorphism

19. The _________________ declares that a derived class is allowed to override a method.

a) void keyword
b) protected keyword
c) base keyword
d) virtual keyword

20. A class that is not intended to be instantiated, but used only as a base class, is called
a(n)________________.

a) dummy class
b) subclass
c) virtual class
d) abstract class

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 7 of 8

21. Consider the classes below, declared in the same file:

class University
{
int u;
public University ()
{
u = 7;
}
}

class College: University


{
int c;
public College ()
{
c = 8;
}
}

Which of the statements below is false?

a) Both variables u and c are instance variables.


b) After the constructor for class College is executed, the variable u will have the value 7.
c) After the constructor for class College is executed, the variable c will have the value 8.
d) A reference to class University can be treated as a reference to class College.

22. In an inheritance relationship, the _________________ is the general class.

a) derived class
b) base class
c) dependent class
d) child class

23. Which of the following Object Declaration is Valid?

a) Computers c = new Computers (NameTextBox.Text)


b) Computers = new c (NameTextBox.Text)
c) Computers (NameTextBox.Text) = c
d) c = Computers (NameTextBox.Text)

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01


Introduction to Object Oriented Programming (IOOP) - CT044-3-1 Page 8 of 8

24. Which of the following is not suitable for operations related to images?

a) List
b) Picture Box
c) Image List
d) Image Property

25. If you write a class with no constructor whatsoever, the compiler will provide
a(n)__________________ .

a) default constructor
b) constructor list
c) parameterized method
d) error message.

Level 1 Asia Pacific University of Technology and Innovation 2017/ 01

You might also like