Submitted by heartin on Mon, 10/05/2015 - 07:44
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.
Submitted by heartin on Mon, 09/14/2015 - 10:49
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?
Submitted by heartin on Sun, 09/13/2015 - 06:48
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
Submitted by heartin on Sat, 09/12/2015 - 19:51
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
Submitted by heartin on Sat, 09/12/2015 - 19:50
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