package inheritance;
public class Class1 {
public static void printMessage()
{
System.out.println("I am in Class1 printMessage");
}
public void printMessage1()
{
System.out.println("I am in Class1 printMessage1");
}
}
package inheritance;
public class Class2 extends Class1 {
public static void printMessage()
{
System.out.println("I am in Class2 printMessage");
}
public void printMessage1()
{
System.out.println("I am in Class2 printMessage1");
}
}
package inheritance;
public class InheritanceLoadingVsRiding {
public static void main(String[] args) {
Class2 c2=new Class2();
Class1 c1=c2;
c1.printMessage();
c1.printMessage1();
c2.printMessage();
c2.printMessage1();
}
}
public class Class1 {
public static void printMessage()
{
System.out.println("I am in Class1 printMessage");
}
public void printMessage1()
{
System.out.println("I am in Class1 printMessage1");
}
}
package inheritance;
public class Class2 extends Class1 {
public static void printMessage()
{
System.out.println("I am in Class2 printMessage");
}
public void printMessage1()
{
System.out.println("I am in Class2 printMessage1");
}
}
package inheritance;
public class InheritanceLoadingVsRiding {
public static void main(String[] args) {
Class2 c2=new Class2();
Class1 c1=c2;
c1.printMessage();
c1.printMessage1();
c2.printMessage();
c2.printMessage1();
}
}
0 comments:
Post a Comment