A class which is declared as abstract must have at least one abstract method.

Practice More Questions From: Quiz 3 : Abstract Classes

Q:

We can instantiate an abstract class.

Q:

An abstract class can only contain abstract methods.

Q:

A non-abstract class can contain an abstract method.

Q:

A class which is declared as abstract must have at least one abstract method.

Q:

What will be the output of the following program? abstract class A { public void display(); } class B extends A { @Override public void display() { System.out.print(“Two”); } public void reset() { System.out.print(“Zero”); } } public class C { public static void main(String args[]) { A screen = new B(); screen.display(); screen.reset(); } }

Q:

What will be the output of the following program? abstract class Calculation { abstract void calculate(int number); } class Summation extends Calculation { int result; @Override public void calculate(int number) { this.result = number + number; } } class Main { public static void main(String args[]) { Summation summation = new Summation(); summation.result = 0; summation.calculate(2); System.out.print(summation.result); } }

Q:

What will be the output of the following program? abstract class Calculation { abstract void calculate(int number); } class MySummation extends Calculation { int result; @Override public void calculate(int number) { if (number < 10) { this.result = 590; } else { this.result = number + number; } } } class Main { public static void main(String args[]) { MySummation mySummation1 = new MySummation(); mySummation1.calculate(9); MySummation mySummation2 = new MySummation(); mySummation2.calculate(10); System.out.print(mySummation1.result); System.out.print(", "); System.out.print(mySummation2.result); } }

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments