OOP Quiz 3 Flashcards

1
Q

The following field has been declared as a member of a Java class.

int length;

Which of the following is correct?

Select one:
‘length’ is instance-level, and has an unknown initial value

‘length’ is instance-level, and has an initial value of 1

‘length’ is class-level, and has an initial value of 0

‘length’ is class-level, and has an unknown initial value

‘length’ is class-level, and has an initial value of 1

‘length’ is instance-level, and has an initial value of 0

A

The correct answer is: ‘length’ is instance-level, and has an initial value of 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When writing a class, what is the return type declared in the signature of its constructor?

Select one:
There is no return type declared

void

The type being constructed

A

There is no return type declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is not an object oriented programming concept in Java?

Select one:
Narrowing conversion 
Abstraction
Polymorphism
Inheritance
Encapsulation
A

The correct answer is: Narrowing conversion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In the ‘Rectangle’ class, I would like to define a method to compare two rectangles’ area. Which of the following is the best choice?

Select one:
a. public static final int compareArea(Rectangle rec1, Rectangle rec2)

b. public static int compareArea(Rectangle rec1, Rectangle rec2)
c. Public static void compareArea(Rectangle rec1, Rectangle rec2)
d. Public int compareArea(Rectangle rec1, Rectangle rec2)
e. Public static compareArea(Rectangle rec1, Rectangle rec2)

A

b. public static int compareArea(Rectangle rec1, Rectangle rec2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Given a class Dog, which has a constructor which takes a single int argument (dog’s age), which of the below is syntactically correct in Java?

Select one:

a. Dog d = new Dog(5.0);
b. Dog d = Dog(5);
c. Dog d = new Dog(int 5);
d. Dog d = new Dog(5);
e. Dog d.age = 5;

A

d. Dog d = new Dog(5);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The source file Test.java is as follows

class Test{

private int data=40;

public void msg(){

	System.out.println(“Data=“+data);

}

}

Which of the following is correct?

Select one:
a. It will fail to compile, as the Test class need to add ‘public’. 

b. It will fail to compile, as there is no constructor.
c. It will compile successfully.
d. It will fail to compile, as the data is private, the msg() can’t access it.
e. It will fail to compile, as the data should not be initiated directly, in a constructor instead.

A

The correct answer is: It will compile successfully.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In the Q6’s code, how do we read the ‘data’ in another class?

Select one:
a. The ‘data’ attribute is not accessible directly outside of ‘Test’ class.

b. Test t;
int a = t.data;

c. Test t = new Test();
int a = t.data;
d. Test t = new test();
int a = Test.msg(); 

e. int a = Test.data;

A

a. The ‘data’ attribute is not accessible directly outside of ‘Test’ class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the contribution of the “new” keyword in the object creation in Java?

Select one:

a. Initialization
b. Instantiation
c. Declaration
d. Definition

A

b. Instantiation Correct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the advantages of encapsulation in OOP?

Select one:

a. all of the above Correct
b. provides total control over data
c. supports modularity
d. supports maintenance

A

a. all of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What components/constructs in Java support object oriented features?

Select one:

a. For loops
b. “Private” keyword
c. method overloading
d. both method overloading and “Private” keyword
e. Switch statements

A

d. both method overloading and “Private” keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly