Home > Java Programming > Abstract > Questions and Answers
01. |
Abstract class Foo { Public static void main (String args[]){ System.out.println (“Fooâ€); } }
| |||||||||||
|
02. |
Abstract class Foo { Foo () {} } Can we declare a constructor in an abstract class? | |||||||||||
|
03. |
Abstract class Foo { Abstract Foo ( ); } Can we declare constructor as abstract?
| |||||||||||
|
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. | |||||||||||||||
|
05. |
Public abstract class Wow { Private int wow; Public Wow (int wow) { This.wow=wow; } Public void wow ( ) {}
Private void wowiz ( ) {} } | |||||||||||
|
06. | Which of the following is correct (valid) declaration of a class? | |||||||||||
|
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 */} } | |||||||||||||||
|
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? | |||||||||||||||
|
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; } | |||||||||||
|
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 | |||||||||||||||
|