Core Java - Interview Questions and Answers for 'Overriding' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Overriding' - 24 question(s) found - Order By Rating

 Q1. How many VTables are there for each class ? Core Java
Ans. There is one VTable for each class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding      intermediate        rare


 Q2. How is the virtual method table implemented in Java?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts      expert        rare


 Q3. What is virtual table with respect to method overriding in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     vtable  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q4. Difference between static and dynamic binding ?Design
Ans. Static binding happens at the compile time whereas dynamic binding happens at runtime.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static vs dynamic binding  overriding     Asked in 1 Companies      basic        frequent


 Q5. What is Overriding ?Core Java
Ans. Overriding refers to the Methods with same name and parameters, such that the later over rides the former method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops  oops concepts  overriding     Asked in 1 Companies      basic        frequent


 Q6. Is Runtime Polymorphism possible without Inheritance ?Core Java
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     runtime polymorphism  object oriented programming (oops)  oops concepts  method overriding  inheritance  object oriented programming (oops)  oops concepts


 Q7. Can we override the overloaded methods too ?Core Java
Ans. Yes. Both concepts are independent of each other. Overriding depends on the methods with same name and signature whereas Overloading on same name but with different signatures. All definitions of an overloaded method can be individually overridden in the derived class.

For example -

Class A has overloaded methods "public void myMethod(String str)" and "public void myMethod(int x)"

We can have derived class ClassB extends ClassA and hence can override both methods myMethod(String str) and myMethod(int x) in ClassB

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overloading  overriding     Asked in 1 Companies


 Q8. What is "dynamic method dispatch" in java ?Core Java
Ans. dynamic method dispatch is a process in which a call to an
overridden method is resolved at runtime rather than at compile-time. This is used to achieve runtime polymorphism in java.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overriding  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q9. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ? Core Java
Ans. Java identifies the method to be called at runtime by the object that is being referenced.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q10. Which of the two - compile time and run time polymorphism - requires signature of the method to be different ?Core Java
Ans. runtime polymorphism or method overriding doesn't require method name and signature to be different whereas compile time polymorphism or method overloading requires method name to be same but the signature to be different.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q11. Can we override an abstract method with abstract method in the derived class ?Core Java
Ans. Yes, but in that case the derived class itself should be abstract. We cannot have an object of a class without definition for the method which has been declared abstract in the parent.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overriding  overriding abstract methods  abstract methods


 Q12. Can we override abstract methods ?Core Java
Ans. Abstract methods are the methods that need to be overridden in the derived class ( either as implementing method or again abstract method ) so it's not only allowed but its required to override abstract method in the derived class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overriding  abstract methods  overriding abstract methods


 Q13. Any real life example of Overloading and Overridding ?
Ans. All members of a family share a common last name and thats how outsiders recognize them, but to recognize individual team members , we need an overloaded name and hence we use First Name along with Last Name to uniquely identify.

Some members of a family have a Nick Name as the real name is very long or hard to call. So the Nick name overrides the Original Name in certain circumstances.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overloading  overriding     Asked in 2 Companies


 Q14. Can we reduce the visibility of the overridden method ?Core Java
Ans. No

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overriding   access specifier   oops   java   yes-no


 Q15. Does java allow overriding static methods ?Core Java
Ans. No. Static methods belong to the class and not the objects. They belong to the class and hence doesn't fit properly for the polymorphic behavior.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   static   static method   overriding      intermediate

Try 3 Question(s) Test


 Q16. What restrictions are placed on method overriding?
Ans. Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   overriding      basic        frequent

Try 2 Question(s) Test


Very Frequently asked to fresh graduates and less experienced. Favorite question in Walk in drives. Frequently asked in Indian Services companies.
  Q17. Difference between Overloading and Overriding ?Core Java
Ans. Overloading - Similar Signature but different definition , like function overloading.

Overriding - Overriding the Definition of base class in the derived class.

  Sample Code for overloading

  Sample Code for overriding

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   overloading   overriding   oops concepts   basic interview question   overloading vs overriding     Asked in 86 Companies      basic        frequent

Try 1 Question(s) Test


 Q18. What is a Final Method ?Core Java
Ans. A Method that cannot be overriden in the sub class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   java keywords   final   final method   overriding   basic interview question      basic        frequent

Try 1 Question(s) Test


 Q19. Can we reduce the visibility of the inherited or overridden method ?Core Java
Ans. No.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   access specifier   overriding   overridding   inheritence   yes-no


 Q20. What are points to consider in terms of access modifier when we are overriding any method?Core Java
Ans. 1. Overriding method can not be more restrictive than the overridden method.

reason : in case of polymorphism , at object creation jvm look for actual runtime object. jvm does not look for reference type and while calling methods it look for overridden method.

If by means subclass were allowed to change the access modifier on the overriding method, then suddenly at runtime when the JVM invokes the true objects version of the method rather than the reference types version then it will be problematic

2. In case of subclass and superclass define in different package, we can override only those method which have public or protected access.

3. We can not override any private method because private methods can not be inherited and if method can not be inherited then method can not be overridden.

  Sample Code for Overriding

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   overriding   access specifier   inheritence   oops   polymorphism  object oriented programming (oops)  oops concepts   runtime polymorphism  object oriented programming (oops)  oops concepts     Asked in 4 Companies

Try 2 Question(s) Test


 Q21. what is covariant return type? Core Java
Ans. co-variant return type states that return type of overriding method can be subtype of the return type declared in method of superclass. it has been introduced since jdk 1.5

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   inheritence   overriding   covariant return type   jdk5   advanced     Asked in 3 Companies      expert


 Q22. How compiler handles the exceptions in overriding ?Core Java
Ans. 1)The overriding methods can throw any runtime Exception , here in the case of runtime exception overriding method (subclass method) should not worry about exception being thrown by superclass method.

2)If superclass method does not throw any exception then while overriding, the subclass method can not throw any new checked exception but it can throw any runtime exception

3) Different exceptions in java follow some hierarchy tree(inheritance). In this case , if superclass method throws any checked exception , then while overriding the method in subclass we can not throw any new checked exception or any checked exception which are higher in hierarchy than the exception thrown in superclass method

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   overriding   exceptions   inheritence   inheritance  object oriented programming (oops)  oops concepts   oops


 Q23. Overridden methods must have the same ...

a. name
b. name and argument list
c. name, argument list, and return type
d. name, argument list, return type and belong to the same class
Ans. name and argument list

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   overriding

Try 2 Question(s) Test


 Q24. How is static and dynamic polymorphism achieved in Java ?Core Java
Ans. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static polymorphism  object oriented programming (oops)  oops concepts   dynamic polymorphism  object oriented programming (oops)  oops concepts   polymorphism  object oriented programming (oops)  oops concepts   overloading   overriding   broadridg     Asked in 1 Companies      basic        frequent


 Q25. Which of the following can be overridden ?Core Java
a. final instance methods
b. final static methods
c. non final instance methods
d. non final static methods

Ans.c. non final instance methods

 Q26. What will be the ouput upon executing main method ?

public class Vehicle {
   public void move(){
      System.out.println("Vehicle is moving");
   }
}

public class Car {
   public void move(){
      super().move();
      System.out.println("Car is moving");
   }

   public static void main(String[] args){
      new Car().move();
   }
}
Core Java
a. Vehicle is moving
b. Car is moving
c. Vehicle is moving Car is moving
d. Compilation Error

Ans.d. Compilation Error

 Q27. What will be the output upon exceuting main method ?

public class Vehicle {
   private void move(){
      System.out.println("Vehicle is moving");
   }
}

public class Car extends Vehicle{
   public void move(){
      System.out.println("Car is moving");
   }

   public static void main(String[] args){
      Vehicle vehicle = new Car();
      vehicle.move();
   }
}
Core Java
a. Vehicle is moving
b. Car is moving
c. Vehicle is moving Car is moving
d. Compilation error

Ans.d. Compilation error

 Q28. What will be the output upon executing the main method ?

public class Vehicle {
   public void move(){
      System.out.println("Vehicle is moving");
   }
}

public class Car extends Vehicle{
   public void move(){
      System.out.println("Car is moving");
   }

   public static void main(String[] args){
      Vehicle vehicle = new Vehicle();
      ((Car)vehicle).move();
   }
}
Core Java
a. Vehicle is moving
b. Car is moving
c. Cimpilation Error
d. Runtime Exception

Ans.d. Runtime Exception

 Q29. Overriding is not possible without ..Core Java
a. Inheritance
b. Composition
c. Inner Classes
d. Abstract Classes

Ans.a. Inheritance


Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: