TOTAL QS = 10Time [ 00 : 00 : 00 ]
00:00:00

Java Inheritance Basics Online Practice Test 2

Instructions

Total Questions: 10

Total Minutes: 10

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on the basics of Java Inheritance. This practise-test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Java basics.

Go through Java Theory Notes on Inheritance before attempting this test.

All the Best

Challenge SCORE

0 / 10

Take This Exam
1) What is the maximum number of levels possible in a Multilevel Inheritance in Java?
2) What is the output of the below java program with Constructors and Inheritance?
class Processor
{
  Processor()
  {
    System.out.print("Inside Processor() Constructor. ");
  }
}
class I3Processor extends Processor
{
  I3Processor()
  {
    System.out.print("Inside I3Processor() Constructor. ");
  }
}
class I5Processor extends I3Processor
{
  I5Processor()
  {
    System.out.print("Inside I5Processor() Constructor. ");
  }
}

public class JavaInheritance2
{
  public static void main(String[] args)
  {
    I5Processor i5 = new I5Processor();
  }
}
3) What is the output of the below Java program with Constructors using Inheritance?
class Ant
{
  Ant(String name)
  {
    System.out.print("Inside Ant(String) Constructor. ");
  }
}
class WildAnt extends Ant
{
  WildAnt()
  {
    System.out.print("Inside WildAnt() Constructor. ");
  }
}

public class Inheritance3
{
  public static void main(String[] args)
  {
    WildAnt wa = new WildAnt();
  }
}
4) If a class is not subclassed by any class, then defining a default constructor is not mandatory in Java. State TRUE or FALSE.
5) What is the output of the below Java program?
final class Bus
{
  void show()
  {
    System.out.print("Generic Bus. ");
  }
}
class ElectricBus extends Bus
{
  void show()
  {
    System.out.println("Electric Bus. ");
  }
}
public class Inheritance4
{
  public static void main(String[] args)
  {
    ElectricBus eb = new ElectricBus();
    eb.show();
  }
}
6) A Superclass reference can refer to a Subclass Object without casting. State TRUE or FALSE.
7) A superclass reference can not be used to invoke a method or variable of the subclass. State TRUE or FALSE.
8) A subclass object can be used to invoke (call) a method or property of the superclass. State TRUE or FALSE.
9) What is the output of the below Java program on the references of Superclass and Subclass?
class Food
{
  void show()
  {
    System.out.print("FOOD ");
  }
}
class Bread extends Food
{
  void toast()
  {
    System.out.print("TOASTED ");
  }
}
public class Inheritance5
{
  public static void main(String[] args)
  {
    Food foo = new Food();
    foo.show();
    Food foo2 = new Bread();
    foo2.show();
    Bread br = new Bread();
    br.toast();
    br.show();
  }
}
10) What is the output of the below Java program using Inheritance?
class Furniture
{
  void show()
  {
    System.out.println("Made of Wood. ");
  }
}
class Sofa extends Furniture
{
  void addCushion()
  {
    System.out.println("Added. ");
  }
}
public class Inheritance6
{
  public static void main(String[] args)
  {
    Furniture fur = new Sofa();
    fur.addCushion();
  }
}

 

 

Show some care. Like or Subscribe.

C MCQ App by ExamTray (Give us 5*)

EXAMTRAY C MCQ android app link

Java MCQ App by ExamTray (Give us 5*)

EXAMTRAY Java MCQ android app link
ALL MCQ App by ExamTray (Give us 5*) EXAMTRAY android app link
WUnsaved Whatsapp msg to Unknown(Give us 5*) WUnsaved android app link
Virtual Tape GPS (Give us 5*) Virtual Tape GPS android app link