31. Given the following piece of code:
public class School{
public abstract double numberOfStudent();
}
which of the following statements is true?
public class School{
public abstract double numberOfStudent();
}
which of the following statements is true?
32. Which of the following class definitions defines a legal abstract class?
33. Which of the following declares an abstract method in an abstract Java class?
34. Which of the following statements regarding abstract classes are true?
35. Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct?
1. A a = new A();
2. A a = new B();
3. B b = new A();
4. B b = new B();
1. A a = new A();
2. A a = new B();
3. B b = new A();
4. B b = new B();
36. Which of the following is a correct interface?
37. Determine output of the following code.
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");
}
}
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");
}
}
38. Given the following piece of code:
public interface Guard{
void doYourJob();
}
abstract public class Dog implements Guard{ }
which of the following statements is correct?
public interface Guard{
void doYourJob();
}
abstract public class Dog implements Guard{ }
which of the following statements is correct?
39. In Java, declaring a class abstract is useful
40. What will be the output?
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();
}
}
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();
}
}
Read More Section(Interfaces and Abstract Classes)
Each Section contains maximum 100 MCQs question on Interfaces and Abstract Classes. To get more questions visit other sections.