Test Series - java

Test Number 66/64

Q: What is the output of the below Java program with multiple abstract classes?
abstract class Editor
{
  abstract void show();
}

abstract class Author extends Editor
{
  abstract void print();
}

class Office extends Author
{
  void show()
  {
    System.out.println("Editor method");
  }
  void print()
  {
    System.out.println("Author method");
  }
}

public class AbstractClassTesting4
{
  public static void main(String[] args)
  {
    Editor ed = new Office();
    ed.show();

    Author au = new Office();
    au.print();	
  }
}
A. Editor method Editor method
B. Author method Author method
C. Editor method Author method
D. Compiler error
Solution: An abstract class can inherit from another abstract class. The final concrete class inheriting the last abstract in the chain should implement all the abstract methods above it.
Q: An object of multi-level inherited abstract class can not be created in memory? State TRUE or FALSE.
A. TRUE
B. FALSE
C.  -
D.  -
Solution: True. You can not create objects out of an abstract class whether it is single level or multilevel.
Q: An abstract class with 100% abstract methods is equivalent to ______.
A. Concrete class
B. Virtual Class
C.  Interface
D. All the above
Solution: An interface contains only abstract methods. So it is comparable to a 100% abstract class.
Q: What is the output of the below Java program with an abstract class?
public abstract class AbstractClassTest5
{
  public static void main(String[] args)
  {
    System.out.println("Inside Main() method..");
  }
}
A. No output
B. Compiler error
C. Inside Main() method..
D. None of the above
Solution: It is perfectly allowed to define a public abstract class as long as you do not create objects of it. Remember that the name of the JAVA file is the name of the public class.
Q: What is the output of the below Java code with an abstract class and inner class?
public abstract class AbstractClassTest6
{
  class Anonymous
  {
    int a=5;
  }
  public static void main(String args[])
  {
    System.out.print("Inner class is present..");	
  }	
}
A. Compiler error
B. Inner class is present..
C. No output
D. None of the above
Solution: Inner classes are allowed to be written inside an abstract class. So, the program compiles successfully. But to use that inner class, subclassing is necessary.
Q: Choose a correct statement about abstract classes?
A. An abstract class can extend a concrete class
B. An abstract class can extend another abstract class
C. An abstract class can implement any number of interfaces.
D. All the above.
Solution: Yes. Abstract classes can implement interfaces and extend other classes.
Q: Choose correct statements about an Abstract class in Java?
A. An abstract class implementing an Interface, need not implement methods of an interface
B. An abstract class extending another abstract class, need not define methods of the super abstract class.
C.  The first subclass of an abstract class should define all the abstract methods inherited from all the interfaces and super abstract classes.
D. All the above
Solution:  -
Q: Just like an Interface, you can define constants in abstract classes in Java. State TRUE or FALSE.
A. TRUE
B. FALSE
C.  -
D.  -
Solution: TRUE
Q: Abstract classes support ____ inheritance.
A. Multiple
B. Multilevel
C.  -
D.  -
Solution: Just like a concrete/normal class in Java, abstract classes support multilevel inheritance only. You can extend only from one super class.
Q: An abstract class can define ____ inside of it.
A. Inner abstract class
B. Inner concrete class
C. static methods
D. All the above
Solution: no solution

You Have Score    /10