Saturday, 1 August 2009

Java Certification Question 0051

What will happen when you attempt to compile and run the following code

class Base{

protected int i = 99;

}

public class Ab{

private int i=1;

public static void main(String argv[]){

Ab a = new Ab();

a.hallow();

}

abstract void hallow(){

System.out.println("Claines "+i);

}

}

1) Compile time error
2) Compilation and output of Claines 99
3) Compilation and output of Claines 1
4) Compilation and not output at runtime


Answer 1:

1) Compile time error

When compiled with JDK 1.1 the following error is produced.

Abstract and native methods can't have a body: void hallow() abstract void hallow()

No comments: