Java Interfaces And Abstract Classes MCQ

Answer all questions carefully. After submission, you will see a detailed result and answer review.

Question 1
What will be the output? <pre class="prettyprint"> 1. public interface InfA{ 2. protected String getName(); 3. } public class Test implements InfA{ public String getName(){ return "test-name"; } public static void main (String[] args){ Test t = new Test(); System.out.println(t.getName()); } } </pre>
Question 2
Which of the following class definitions defines a legal abstract class?
Question 3
Determine output of the following code. <pre class="prettyprint"> interface A { } class C { } class D extends C { } class B extends D implements A { } public class Test extends Thread{ public static void main(String[] args){ B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C) System.out.println("b is an instance of C"); } } </pre>
Question 4
What is the output for the below code ? <pre class="prettyprint"> interface A{ public void printValue(); } 1. public class Test{ 2. public static void main (String[] args){ 3. A a1 = new A(){ 4. public void printValue(){ 5. System.out.println("A"); 6. } 7. }; 8. a1.printValue(); 9. } 10. } </pre>
Question 5
What happens if the following program is compiled and executed? <pre class="prettyprint"> interface MyInterface{ void display(); } interface MySubInterface extends MyInterface{ void display(); } public class Test implements MySubInterface{ public void display(){ System.out.print("Welcome to Examveda."); } public static void main(String args[]){ Test t = new Test(); t.display(); } } </pre>
Question 6
<pre class="prettyprint"> interface Test{ int p = 10; //line 1 public int q = 20; //line 2 public static int r = 30; //line 3 public static final int s = 40; //line 4 } </pre> Which of the above line will give compilation error?
Question 7
What will be the output when the following program is compiled and executed? <pre class="prettyprint"> abstract class TestAbstract{ String my_name; String myName(){ my_name = "Examveda"; return my_name; } abstract void display(); } public class Test extends TestAbstract{ void display(){ String n = myName(); System.out.print("My name is "+ n); } public static void main(String args[]){ Test t = new Test(); t.display(); } } </pre>
Question 8
What will be the output? <pre class="prettyprint"> interface A{ public void method(); } class One{ public void method(){ System.out.println("Class One method"); } } class Two extends One implements A{ public void method(){ System.out.println("Class Two method"); } } public class Test extends Two{ public static void main(String[] args){ A a = new Two(); a.method(); } } </pre>
Question 9
Given the following piece of code: <pre class="prettyprint"> public class School{ public abstract double numberOfStudent(); } </pre> which of the following statements is true?
Question 10
Which two of the following are legal declarations for abstract classes and interfaces? <p>1. final abstract class Test {}<br />2. public static interface Test {}<br />3. final public class Test {}<br />4. protected abstract class Test {}<br />5. protected interface Test {}<br />6. abstract public class Test {}</p>