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

Java Method Overriding Basics Online Practice Test 1

Instructions

Total Questions: 22

Total Minutes: 22

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on the basics of Java Method Overriding. 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 Method Overriding before attempting this test.

All the Best

Challenge SCORE

0 / 22

Take This Exam
1) What is method overriding in Java?
2) Method Overriding is useful to add extra functionality or code to a method of subclass with the same name as the inherited method. State TRUE or FALSE.
3) It is not mandatory to override all or a few methods of the Superclass. State TRUE or FALSE.
4) Why should a method be overridden in Java instead of writing a method with a different name?
5) The Method-Overloading and Method-Overriding are not the same. State TRUE or FALSE.
6) What is the output of the below Java program with Method Overriding?
class Bus
{
  void seatingCapacity()
  {
    System.out.println("Superclass Seats=32");
  }
}
class ElectricBus extends Bus
{
  void seatingCapacity()
  {
    System.out.println("Subclass Seats=20");
  }
  void showInfo()
  {
    seatingCapacity();
    this.seatingCapacity();
  }
}
public class MethodOverriding1
{
  public static void main(String[] args)
  {
    ElectricBus eb = new ElectricBus();
    eb.showInfo();
  }
}
7) What is the output of the below Java program with Method Overriding and SUPER keyword?
class Car
{
  void showTransmission()
  {
    System.out.println("Transmission Manual");
  }
}
class ElectricCar extends Car
{
  void showTransmission()
  {
    System.out.println("Transmission AMT");
  }
  void showInfo()
  {
    this.showTransmission();
    super.showTransmission();
  }
}
public class MethodOverriding2
{
  public static void main(String[] args)
  {
    ElectricCar ec = new ElectricCar();
    ec.showInfo();
  }
}
8) Identify INVALID Java Method Overriding in the below code snippets? Follow the notation "superclassMethod" and "subclassMethod".
9) A successful Method Overriding calls the method of ___ in Java.
10) A failed method overriding calls the method of a ___ in Java.
11) What is the output of the below Java program with method overriding?
class Cat
{
  int jumpingHeight(int weight)
  {
    System.out.println(10);
    return 10;
  }
}
class WildCat extends Cat
{
  void jumpingHeight(int weight)
  {
    System.out.println("20");
  }
}
public class MethodOverriding3
{
  public static void main(String[] args)
  {
    WildCat wc = new WildCat();
    wc.jumpingHeight(30);
  }
}
12) What is the output of the below Java program with Method Overriding?
class Sparrow{ }
class BigSparrow extends Sparrow { }
class Cat2
{
  Sparrow jumpingHeight(int weight)
  {
    System.out.println(40);
    return new Sparrow();
  }
}
class WildCat2 extends Cat2
{
  BigSparrow jumpingHeight(int weight)
  {
    System.out.println("50");
    return new BigSparrow();
  }
}
public class MethodOverriding4
{
  public static void main(String[] args)
  {
    WildCat2 wc = new WildCat2();
    wc.jumpingHeight(80);
  }
}
13) What is the output of the below Java program with method overriding?
class Steel
{
  void setGrade(int g)
  {
    System.out.print(",GRADE="+g);
  }
}
class CarbonSteel extends Steel
{
  void setGrade(char grade)
  {
    System.out.print(",Grade="+grade);
  }
}
public class MethodOverriding5
{
  public static void main(String[] args)
  {
    Steel s = new CarbonSteel();
    s.setGrade(5);
    s.setGrade('A');
  }
}
14) What is the output of the below Java program with method overriding?
class Wood
{
  void setQuality(int q)
  {
    System.out.print(",QUALITY="+q);
  }
}
class PlyWood extends Wood
{
  void setQuality(char qual)
  {
    System.out.print(",quality="+qual);
  }
}
public class MethodOverriding6
{
  public static void main(String[] args)
  {
    PlyWood pw = new PlyWood();
    pw.setQuality(10);
    pw.setQuality('B'); //ASCII of B=66
  }
}
15) What is the output of the below Java program with method overriding?
class Amplifier
{
  void addGain(int a)
  {
    System.out.println((a + 10)+"dB");
  }
}
class DigitalAmplifier extends Amplifier
{
  void addGain(int a)
  {
    super.addGain(a+5);
  }
}
public class MethodOverriding7
{
  public static void main(String[] args)
  {
    DigitalAmplifier da = new DigitalAmplifier();
    da.addGain(12);
  }
}
16) If the method signature of a Superclass and the method signature of a Subclass are the same, then the subclass method is said to be _____ the superclass's method.
17) A method of a Superclass can not override the method of the Subclass. State TRUE or FALSE.
18) Method overriding increases the burden on the JVM in terms of runtime checks and resolution. State TRUE or FALSE.
19) What are the advantages of Method Overriding in Java?
20) An Overridden method is the method of ____ class and the overriding method is the method of ___ class.
21) To successfully override a superclass method in Java, the access modifier of the method of the subclass can be ___ restrictive.
22) Which is the correct way of overriding a method throwing exceptions in Java?

 

 

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