Lakshya Education MCQs

Question: 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();
A.1 and 2
B.2 and 4
C.3 and 4
D.1 and 3
E.2 and 3
Answer: Option B

Submit Answer & Explaination

Earn Reward Points by submitting Detailed Explaination for this Question

More Questions on This Topic :

Question 1. Which of the following is a correct interface?
  1.    interface A { void print() { } }
  2.    abstract interface A { print(); }
  3.    abstract interface A { abstract void print(); { }}
  4.    interface A { void print(); }
Answer: Option D
Question 2. 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");
  1.    Nothing.
  2.    b is an instance of A.
  3.    b is an instance of C.
  4.    b is an instance of A followed by b is an instance of C.
Answer: Option D
Question 3. Given the following piece of code:
public interface Guard{
void doYourJob();
abstract public class Dog implements Guard{ }
which of the following statements is correct?
  1.    This code will not compile, because method doYourJob() in interface Guard must be defined abstract.
  2.    This code will not compile, because class Dog must implement method doYourJob() from interface Guard.
  3.    This code will not compile, because in the declaration of class Dog we must use the keyword extends instead of implements.
  4.    This code will compile without any errors.
Answer: Option D
Question 4. Which of the following statements regarding abstract classes are true?
  1.    An abstract class can be extended.
  2.    A subclass of a non-abstract superclass can be abstract.
  3.    A subclass can override a concrete method in a superclass to declare it abstract.
  4.    An abstract class can be used as a data type.
  5.    All of the above
Answer: Option E
Question 5. Which of the following class definitions defines a legal abstract class?
  1.    class A { abstract void unfinished() { } }
  2.    class A { abstract void unfinished(); }
  3.    abstract class A { abstract void unfinished(); }
  4.    public class abstract A { abstract void unfinished(); }
Answer: Option C
Question 6. Which of the following declares an abstract method in an abstract Java class?
  1.    public abstract method();
  2.    public abstract void method();
  3.    public void abstract Method();
  4.    public void method() {}
  5.    public abstract void method() {}
Answer: Option B

Check all Questions in this Topic : Click HERE