Welcome Guest | Sign in | Register

Home > Java Programming > Abstract > Questions and Answers

01. Abstract class Foo {
Public static void main (String args[]){
System.out.println (“Foo”);
}
}
A. compile time error B. runtime error
C. foo D. none of the above

Answer and Explanation

Answer: foo

Explanation:
Here Foo is a abstract class. An abstract class can contain non-abstract method.

In the example, main ( ) method is a non-abstract method so it will not throw any error. It will display Foo.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. Abstract class Foo {
Foo () {}
}

Can we declare a constructor in an abstract class? 
A. Yes B. No
C. Cannot be determined D. None of the above

Answer and Explanation

Answer: Yes

Explanation:
We can declare a constructor in an abstract class.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Abstract class Foo {
Abstract Foo ( );
}

Can we declare constructor as abstract?
A. Yes B. No
C. Cannot be determined D. None of the above

Answer and Explanation

Answer: No

Explanation:
Abstract methods will not have implementation. If you want to implement then you should do it through the child class. Here in the example, constructor Foo( ) is declared as abstract.

Actually constructors are not inherited to child class, constructor are specific to class if you try to make constructor as abstract then it will throw an compile time error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Which three of the following are true?
a).An abstract class cannot be instantiated
b) An interface can extend multiple interfaces
c) All methods in abstract class must be abstract
d) If a class B directly extends class A , then class B must implement all the abstract methods which are declared in class A
e) If concrete class C extends concrete class B, and B implements interface A , then all the methods from interface A can be invoked on an instance of C.
A. A,B,C B. A,C,E
C. A,B,E D. B,C,E
E. B,D,E

Answer and Explanation

Answer: A,B,E

Explanation:
Option a) is true because abstract

Option b) is true. The interface always has public static abstract methods. Abstract methods of parent class should be implemented in child class 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. Public abstract class Wow {
Private int wow;
Public Wow (int wow) {
This.wow=wow;
}
Public void wow ( ) {}
Private void wowiz ( ) {}
}
A. Compiles without any error B. It will not compile because abstract class cannot have private methods.
C. It will not compile because abstract class cannot have instance variables. D. It will not compile because abstract class must have atleast one abstract method.

Answer and Explanation

Answer: Compiles without any error

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. Which of the following is correct (valid) declaration of a class?
A. public abstract class Car{
Protected void acc();
}
B. public interface class Car{
Protected abstract void acc ( );
}
C. public abstract class Car{
Protected abstract void acc ( );
}
D. public abstract class Car{
Protected abstract void acc (){
}
}

Answer and Explanation

Answer: public abstract class Car{
Protected abstract void acc ( );
}

Explanation:
In the first option a) method is not abstract so it should have implementation but in the example it is not there.

In the second option b) method is protected, actually interface methods are public abstract by default so it is not the Answer.

In the fourth one method is abstract but still it is implemented, so that is not the Answer.

So finally c) is the Answer.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. Given:
1. public abstract class Shape {
2. private int x;
3. private int y;
4. public abstract void draw();
5. public void setAnchor(int x, int y) {
6. this.x = x;
7. this.y = y;
8. }
9. }

Which two classes use the Shape class correctly? (Choose two.)



A.     public class Circle implements Shape {
private int radius;
}
B.     public abstract class Circle extends Shape {
private int radius;
}
C.     public class Circle extends Shape {
private int radius;
public void draw();
}
D. public abstract class Circle implements Shape {
private int radius;
public void draw();
}
E. public class Circle extends Shape {
private int radius;
public void draw() {/* code here */}
}
F. public abstract class Circle implements Shape {
private int radius;
public void draw() {/* code here */}
}

A. AB B. BE
C. AC D. BD
E. CE

Answer and Explanation

Answer: BE

Explanation:
In ans B , child class is a abstract class thats why it is not implementing any abstract property of Shape, and in ans E child class is normal class it implements abstract property of super class Shape.
Ans A is wrong because we should not use implaments keyword to to implement abstract class.

Ans C is also wrong because whenever you write 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. abstract class Vehicle {
public int speed() { return 0; }
class Car extends Vehicle { public int speed() { return 60; }
class RaceCar extends Car { public int speed() { return 150; } ...
RaceCar racer = new RaceCar();
Car car = new RaceCar();
Vehicle vehicle = new RaceCar();
System.out.println(racer.speed() + ", " + car.speed() + ", " + vehicle.speed());
}

What is the result?
A. 0, 0, 0 B. 150, 60, 0
C. Compilation fails. D. 150, 150, 150
E. An exception is thrown at runtime.

Answer and Explanation

Answer: 150, 150, 150

Explanation:
just normal flow of execution.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Given:
abstract public class Employee {
protected abstract double getSalesAmount();
public double getCommision() {
return getSalesAmount() * 0.15;
}
}

class Sales extends Employee {
**// insert method here
}


Which two methods, inserted independently at line **// insert method here, correctly complete the Sales class? (Choose two.)

A. double getSalesAmount() { return 1230.45; }
B. public double getSalesAmount() { return 1230.45; }
C. private double getSalesAmount() { return 1230.45; }
D. protected double getSalesAmount() { return 1230.45; }
A. AB B. CD
C. BD D. AD

Answer and Explanation

Answer: BD

Explanation:
B and D are correct because whenever you override a method you can increase the visibility but you cannot decrease the visibility.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. Given
11. public interface Status {
12. /* insert code here */ int MY_VALUE = 10;
13. }


Which three are valid on line 12? (Choose three.)

A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected
A. ABC B. EFG
C. ADE D. ADF
E. ABD

Answer and Explanation

Answer: ABD

Explanation:
 any variable you declare in interface by default that will be public static final.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



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