Java Basic

Quiz Guidelines

 

Multiple Choice Question

QID: 
437

Consider the following code:

public class MyClass {
  protected int value = 10;
}

Which of the following statements are correct regarding the field value?

Select 1 option

A. It cannot be accessed from any other class.
B. It can be read but cannot be modified from any other class. 
C. It can be modified but only from a subclass of MyClass.
D. It can be read and modified from any class within the same package or from any subclass of MyClass.

Multiple Choice Question

QID: 
436

Which of the following are correct about "encapsulation"?

Select 2 options

A. Encapsulation is same as polymorphism.
B. It helps make sure that clients have no accidental dependence on the choice of representation
C. It helps avoiding name clashes as internal variables are not visible outside.
D. Encapsulation makes sure that messages are sent to the right object at run time.
E. Encapsulation helps you inherit the properties of another class.

Multiple Choice Question

QID: 
435

Select the correct order of restrictiveness for access modifiers... (First one should be least restrictive)

Select 1 option 

A. public < protected < package (i.e. no modifier) < private 
B. public < package (i.e. no modifier) < protected < private 
C. public < protected < private < package (i.e. no modifier) 
D. protected < package (i.e. no modifier) < private < public 
E. depends on the implementation of the class or method. 

Multiple Choice Question

QID: 
434

For object o1 of class A to access a member(field or method) of object o2 of class B, when the member has no access modifier, class B must be...

Select 1 option

A. a subclass of A 
B. in the same package as A is in. 
C. a Super class of A 
D. a subclass but may not be in the same package. 
E. in the same package and must be a Subclass of A. 

Multiple Choice Question

QID: 
433

Given the following definition of class, which member variables are accessible from OUTSIDE the package com.enthu.qb?

package com.enthu.qb;
public class TestClass{
int i;
public int j;
protected int k;
private int l;
}

Select 2 options

A. Member variable i.
B. Member variable j.
C. Member variable k.
D. Member variable k, but only for subclasses.
E. Member variable l.

Pages