inheritance

Quiz Guidelines

 

Multiple Choice Question

QID: 
181

Which statements concerning the following code are true?

class A{
public A() {} // A1
public A(String s) { this(); System.out.println("A :"+s); } // A2
}
class B extends A{
public int B(String s) { System.out.println("B :"+s); return 0; } // B1
}class C extends B{
private C(){ super(); } // C1
public C(String s){ this(); System.out.println("C :"+s); } // C2
public C(int i){} // C3
}

Select 4 options

A. At least one of the constructors of each class is called as a result of constructing an object of class C.
B. Constructor at //A2 will never be called in creation of an object of class C
C. Class C can be instantiated only in two ways by users of this class.
D. //B1 will never be called in creation of objects if class A, B, or C
E. The code will not compile.

Multiple Choice Question

QID: 
180

You want to invoke the overridden method (the method in the base class) from the overriding method (the method in the derived class) named m().

Which of the following constructs which will let you do that?

Select 1 option

A. super.m();
B. super.this();
C. base.m();
D. parent.m();
E. super();

Multiple Choice Question

QID: 
179

Given the following class definition:

class A{
protected int i;
A(int i) { this.i = i; }
}  // 1 : Insert code here

Which of the following would be a valid class that can be inserted at //1 ?

Select 2 options

A. class B {}
B. class B extends A {}
C. class B extends A { B() { System.out.println("i = " + i); } }
D. class B { B() {} }

Multiple Choice Question

QID: 
178

What will the following program print when compiled and run?

class Game{
public void play() throws Exception{
System.out.println("Playing...");
}
}
public class Soccer extends Game{
public void play(){
System.out.println("Playing Soccer...");
}
public static void main(String[] args){
Game g = new Soccer();
g.play();
}
}

Select 1 option

A. It will not compile.
B. It will throw an Exception at runtime.
C. Playing Soccer...
D. Playing...
E. None of these.

Multiple Choice Question

QID: 
177

Which of the following statements are true?

Select 2 options

A. Private methods cannot be overridden in subclasses.
B. A subclass can override any method in a non-final superclass.
C. An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.
D. The parameter list of an overriding method must be a subset of the parameter list of the method that it is overriding.
E. The overriding method may opt not to declare any throws clause even if the original method has a throws clause.

Pages