Welcome Guest | Sign in | Register

Home > Java Programming > Inheritance > Questions and Answers

01. class manager {
private manager(int i) {
System.out.println(1); }
manager(int j){
System.out.println(2); }
public static void main(String args[]){
new manager(1); } }
A. 1 B. 2
C. compile time error D. runtime error

Answer and Explanation

Answer: compile time error

Explanation:
manager(int i) is already defined in manager class, means two constructor with same signature is defined in manager class. So it will throw compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. final abstract class G{
void test(){
System.out.println(“A”);
}
}
Public class Manager extends G{
Void test()
{
System.out.println(“manager”);
}
public static void main(String args[]){
Manager m=new Manager();
m.test();
}
}
A. compile time error B. runtime error
C. manager D. A

Answer and Explanation

Answer: compile time error

Explanation:
when ever you declare class as final you cannot extend that class, in the example above the class G can have either abstract or final but not both. 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. abstract interface class G{
void test();
}
Public class Manager extends G{
Void test()
{
System.out.println(“manager”);
}
public static void main(String args[]){
Manager m=new Manager();
m.test();
}
}
A. compile time error B. runtime error
C. manager D. A

Answer and Explanation

Answer: compile time error

Explanation:
you can not declarea class as both abstract and interface, and inside that class they have declared a test(); but without a method that is also an error. So compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. abstract class G{
void test(){
System.out.println(“A”);
}
}
final class Manager extends G{
Void test()
{
System.out.println(“manager”);
}
public static void main(String args[]){
Manager m=new Manager();
m.test();
}
}
A. compile time error B. runtime error
C. manager D. A

Answer and Explanation

Answer: manager

Explanation:
here child class is final that is not a problem, normal flow of execution will give ans as manager

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. class G{
int I,j;
abstract void test();
}
Public class Manager extends G{
public static void main(String args[]){
}
}
A. compile time error B. runtime error
C. manager D. A

Answer and Explanation

Answer: compile time error

Explanation:
abstract method can be declared only in abstract class , but here abstract method is declared inside a normal class, so it will throw compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. abstract class A{
abstract void test2();
}
Class B extends A
{
Void test1(){
System.out.println(“test”);
}
}
Class manager{
Public static void main(String args[]){
B b=new B();
b.test2();
}
}
A. compile time error B. runtime error
C. test D. none of the above

Answer and Explanation

Answer: compile time error

Explanation:
when ever you extend an abstract class you should implement all the abstract properties from super class, but here it is not done, so it will throw an compile time error. 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.