Welcome Guest | Sign in | Register

Home > Java Programming > Interface > Questions and Answers

01. Interface A {
Void test1();
}
Interface B {
Void test2();
}
Class C implements B {
Public void test1(){
System.out.println(“test1”); }
Public void test2(){
System.out.println(“test2”);
} }
Class Manager{
Public static void main(String args[]){
C c1=new C();
c1.test1();
c1.test2();
} }
A. test1 test2 B. test2 test1
C. compile time error D. runtime error

Answer and Explanation

Answer: test1 test2

Explanation:
An interface can extend another interface but a class can only implement an interface, so here class C implement B, so ans is a)

Report Errors

Name:

Loading...

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

Answer and Explanation

Answer: compile time error

Explanation:
An interface can extend another interface but a class can only implement an interface, so here class Manager extends A, this is not correct so ans is c)

Report Errors

Name:

Loading...

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

Answer and Explanation

Answer: manager

Explanation:
An interface can extend another interface but a class can only implement an interface, so here class Manager implements A, so ans is a)

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. interface A{
Int i=0;
}
interface B extends A{
Int i=1;
}
interface C extends B{
Int i=2;
}
Class Manager implements A
{
Int i=3;
Public static void main(String args[])
{
C c1=(C)new Manager();
System.out.println(c1.i);
}
}
A. 3 B. ClassCastException
C. compile time error D. none of the above

Answer and Explanation

Answer: ClassCastException

Explanation:
Here a class Manager implements A which is an interface so it will not throw any compile time error, but while creating an object we are creating an object of manager and trying to store in an c1 variable which is of type C.actually manager is of type A not of type C.. So it will throw ClassCastException.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. interface A{
Int i=0;
}
interface B extends A{
Int i=1;
}
interface C extends B{
Int i=2;
}

Class Manager implements C
{
Int i=3;
Public static void main(String args[])
{
C c1=(C)new Manager();
System.out.println(c1.i);
}
}
A. 3 B. ClassCastException
C. compiletime error D. none of the above

Answer and Explanation

Answer: 3

Explanation:
Here a class Manager implements C which is an interface so it will not throw any compile time error,and while creating an object we are creating an object of manager and trying to store in an c1 variable which is of type C.and manager is also of type C.. So ans is a)

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. interface A{
Int i=0;
}
interface B extends A{
Int i=1;
}
interface C extends A, B{
Int i=2;
}

Class Manager implements A,B, C
{
Int i=3;
Public static void main(String args[])
{
A a1=new Manager();
System.out.println(((B)(C)(B)a1).i);
}
}
A. 3 B. ClassCastException
C. compiletime error D. 1

Answer and Explanation

Answer: 1

Explanation:
Here a class Manager implements A,B, C which is an interface so it will not throw any compile time error,and while creating an object we are creating an object of manager and trying to store in an a1 variable which is of type any type A,B, C.and manager is also of type A,B, C.. So ans is d)

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. interface A{
public void test(){
System.out.println(1);
}
}
A. 1 B. compile time error
C. runtime error D. none of the above

Answer and Explanation

Answer: compile time error

Explanation:
In an interface all methods are by default public abstract , so interface methods should not have body , here in the example test() method has body so it will throw compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. Interface A{
Int test();
}
Class Manager{
Public static void main(String args[]){
A a1=new A();
a1.test();
} }
A. 1 B. compile time error
C. runtime error D. none of the above

Answer and Explanation

Answer: compile time error

Explanation:
We cannot create an object of an interface, if you try it will throw an error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Interface A {}
Class B{
Public final static void test(){
System.out.println(“test”);
} }
Class C extends B implements A{
Public static void main(String args[]){
New C().test();
C.test(); } }
A. compile time error B. runtime error
C. test test D. none of the above

Answer and Explanation

Answer: test test

Explanation:
It’s a normal flow of execution.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. Interface A{
Public static final int i=10;
Final float f=100.0f;
Static public String S;
}
A. compile time error B. runtime error
C. 100.0f D. 10

Answer and Explanation

Answer: compile time error

Explanation:
In an interface all the variables are public static final, and final variable should be initialized, here variable S is not initialized so it will throw 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.