overriding

Quiz Guidelines

 

Multiple Choice Question

QID: 
48

Given:

interface I {
}

class A implements I {
	
	public void m(){
		
	}
}

abstract class B extends A { //line 1

	public abstract void m(); //line 2
}

class C extends B { //line 3
	
}

 

Select 1 option

A. Class will compile successfully

B. Compilation will fail at line marked as line 1.

C. Compilation will fail at line marked as line 2.

D. Compilation will fail at line marked as line 3.

Descriptive Question

QID: 
39

Given:

public class X implements Z {

public String toString() {

return "I am X";

}

public static void main(String[] args) {

Y myY = new Y();

X myX = myY;

Z myZ = myX;

System.out.println(myZ);

}

}

class Y extends X {

public String toString() {

return "I am Y";

}

}

interface Z {}

What is the reference type of myZ and what is the type of the object it references? 

Multiple Choice Question

QID: 
35

What will be the result of compiling and running the following code?

Select 1 option

class Base{

public short getValue(){ return 1; } //1

}

class Base2 extends Base{

public byte getValue(){ return 2; } //2

}

public class TestClass{

public static void main(String[] args){

Base b = new Base2();

System.out.println(b.getValue()); //3

}

}

A. It will print 1

B. It will print 2.

C. Compile time error at //1

D. Compile time error at //2

E. Compile time error at //3

Multiple Choice Question

QID: 
30

What will the program print?

class Parent{
	
	public void myMethod()
	{
		System.out.println("Parent myMethod");
	}
}

class Child extends Parent{
	
	public static void myMethod()
	{
		System.out.println("Child myMethod");
	}
}

class OverridingCheck {

	public static void main(String args[])
	{
		Parent p = new Child();
		p.myMethod();
	}

}

 

Select 1 option

A. Prints "Parent myMethod"

B. Prints "Child myMethod"

C. Compilation Fails

D. Exception at Runtime

Multiple Choice Question

QID: 
29

What will the program print?

class Parent{
	
	public static void myMethod()
	{
		System.out.println("Parent myMethod");
	}
}

class Child extends Parent{
	
	public void myMethod()
	{
		System.out.println("Child myMethod");
	}
}

class OverridingCheck {

	public static void main(String args[])
	{
		Parent p = new Child();
		p.myMethod();
	}

}

 

Select 1 option

A. Prints "Parent myMethod"

B. Prints "Child myMethod"

C. Compilation Fails

D. Exception at Runtime

Pages