Overriding

Program to illustrate the super.mehodname() feature

class Sample1
{ void display(String s)
{ System.out.println(“Class 1 : “ + s);}
}
class Sample2 extends Sample1
{ void display(String s)
{ super.display(s);
System.out.println(“Class 1 : “ + s);
}
}
class sampledemo
{
public static void main(String[] args)
{ Sample1 s1 = new Sample1();
s1.display(“Job1”);
Sample2 s2 = new Sample2();
s2.display(“Job2”); } }
Output
Class 1 : Job 1
Class 1 : Job 2
Class 2 : Job 2

————-
public static void main(String[] args)
{ Sample1 s1 = new Sample1();
s1.display(“Job1”);
s1 = new Sample2();
s1.display(“Job2”); } }

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.