Welcome Guest | Sign in | Register

Home > Java Programming > Abstract > Questions and Answers

01. interface Data { public void load(); }
abstract class Info { public abstract void load(); }


Which class correctly uses the Data interface and Info class?
A. public class Employee extends Info implements Data {
 public void load() {
/*do something*/ 
}
}
B. public class Employee implements Info extends Data {
public void load() { 
/*do something*/
}
}
C.
public class Employee extends Info implements {
Data public void load(){
/*do something*/
}
public void Info.load(){
/*do something*/
}
}
D. public class Employee implements Info extends Data {
public void Data.load(){
 /*do something*/ 
}
public void load(){
 /*do something*/ 
}
}
E. public class Employee implements Info extends Data {
 public void load(){ 
/*do something*/ 
}
public void Info.load(){
 /*do something*/ 
}
}

Answer and Explanation

Answer: public class Employee extends Info implements Data {

 public void load() {
/*do something*/ 
}
}

Explanation:
whenever you want to use interface then use implements keyword, and during abstract class use extends keyword. Vice versa is not true.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. Given:
abstract class C1 {
public C1() { System.out.print(1); }
}
class C2 extends C1 {
public C2() { System.out.print(2); }
}
class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}

class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}


What is the result?
A. 3 B. 23
C. 32 D. 123

Answer and Explanation

Answer: 123

Explanation:
All constructors are executed in order top (C1) to bottom (C3)

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03.
Which two classes correctly implement both the java.lang.Runnable and the java.lang.
Cloneable interfaces? (Choose two.)

A. public class Session implements Runnable, Cloneable {
public void run();
public Object clone();
}

B. public class Session
extends Runnable, Cloneable {
public void run() { /* do something */ }
public Object clone() { /* make a copy */ }

C. public class Session
implements Runnable, Cloneable {
public void run() { /* do something */ }
public Object clone() { /* make a copy */ }

D. public abstract class Session
implements Runnable, Cloneable {
public void run() { /* do something */ }
public Object clone() { /*make a copy */ }

E. public class Session
implements Runnable, implements Cloneable {
public void run() { /* do something */ }
public Object clone() { /* make a copy */ }
A. AB B. CD
C. AD D. CD

Answer and Explanation

Answer: CD

Explanation:
ANS C and D is correct because these two class implemented interface properly and these two class implemented the methods which exisit in Runnable and Clonable interface

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Given:
public interface A { public void m1(); }
class B implements A { }
class C implements A { public void m1() { } }
class D implements A { public void m1(int x) { } }
abstract class E implements A { }
abstract class F implements A { public void m1() { } }
abstract class G implements A { public void m1(int x) { } }
What is the result?
A. Compilation succeeds. B. Exactly one class does NOT compile.
C. Exactly two classes do NOT compile. D. Exactly four classes do NOT compile.
E. Exactly three classes do NOT compile.

Answer and Explanation

Answer: Exactly two classes do NOT compile.

Explanation:
class B does NOT compile because it gives the error "The type B must implement the inherited abstract
method A.m1()"
class D does NOT compile because it gives the error "The type B must implement the inherited abstract
method A.m1()"
classes E and G does not need to implement the inherited abstract method A.m1() because these classes
(E and G) are abstract

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. abstract class A {
abstract void a1();
void a2() {
}
}
class B extends A {
void a1() {
}
void a2() {
}
}
class C extends B {
void c1() {
}
}
And:
A x = new B();
C y = new C();
A z = new C();
What are four valid examples of polymorphic method calls? (Choose four.)

A. x.a2();
B. z.a2();
C. z.c1();
D. z.a1();
E. y.c1();
F. x.a1();

A. ABCD B. ABDC
C. ABDF D. ABDE
E. BCDE

Answer and Explanation

Answer: ABDF

Explanation:
just normal flow of execution

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06.
Given:
interface DoStuff2 {
float getRange(int low, int high);
}
interface DoMore {
float getAvg(int a, int b, int c);
}
abstract class DoAbstract implements DoStuff2, DoMore {
}
class DoStuff implements DoStuff2 {
public float getRange(int x, int y) {
return 3.14f;
}
}
interface DoAll extends DoMore {
float getAvg(int a, int b, int c, int d);
}


What is the result?
A. The file will compile without error. B. Compilation fails. Only line 7 contains an error.
C. Compilation fails. Only line 12 contains an error. D. Compilation fails. Only line 13 contains an error.
E. Compilation fails. Only lines 7 and 12 contain errors.

Answer and Explanation

Answer: The file will compile without error.

Explanation:
As syntax is correct the above program will compile successfully.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



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