03/02/25 ---------- Q)What are the different uses of "super" keyword? 1)to call the overridden method from overriding method. 2)to call the parent class parameterised constructor explicitly from within the sub class onstructor. Q)Write a Java program in which the following things are implemented. 1.)Method overriding is implemented 2.)Super class reference referencing the sub class object 3.)Method is called using the super class reference. import java.util.Scanner; class Vehicle{ void move(){ System.out.println("every vehicle should move this way."); } } class Car extends Vehicle{ void move(){ System.out.println("As a car I move my own way."); } } class Zeep extends Vehicle{ void move(){ System.out.println("As a zeep I move my own way."); } } class DynamicMethodDispatch { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.print("Which vehicle needed(car/zeep):"); String name=s.next(); Vehicle v; if(name.equals("car")) v=new Car(); else v=new Zeep(); v.move(); } } Q)What is the output of the following program? class A{ } class B extends A{ void x() { System.out.println("hello"); } } class Test{ public static void main(String args[]){ A a=new B(); a.x(); } } Ans:- compilation error. Reason:- Super class doesn't have x() method. Q)Explain about "final" modifier. =>"final" modifier can be associated with variables,methods and classes. =>If a class is"final", it can't be sub classed(inherited). Note:- generally, the bottom most class in the hierarchy is made final. =>Once "final" modifier is applied to a method, it can be inherited but can't be overridden. =>Once "final" modifer is applied to a variable, it becomes a constant. We can't change the value of the constant.