package com.vit;
public class InheritanceDemo {
public static void main(String args[])
{
Super1 super1 = new Super2();
super1.base1();
Super2 super2 = new Super3();
super2.base1();
}
}
class Super1
{
public Super1()
{
System.out.println("with in super1()");
}
public void base1()
{
System.out.println("Base is called from super1");
}
}
class Super2 extends Super1
{
public Super2()
{
System.out.println("with in super2()");
}
public void base2()
{
System.out.println("Base is called from super2");
}
}
class Super3 extends Super2
{
public Super3()
{
System.out.println("with in super3()");
}
public void base1()
{
System.out.println("Base is called from super3");
}
}
---------Answer
with in super1()
with in super2()
Base is called from super2
with in super1()
with in super2()
with in super3()
Base is called from super3
public class InheritanceDemo {
public static void main(String args[])
{
Super1 super1 = new Super2();
super1.base1();
Super2 super2 = new Super3();
super2.base1();
}
}
class Super1
{
public Super1()
{
System.out.println("with in super1()");
}
public void base1()
{
System.out.println("Base is called from super1");
}
}
class Super2 extends Super1
{
public Super2()
{
System.out.println("with in super2()");
}
public void base2()
{
System.out.println("Base is called from super2");
}
}
class Super3 extends Super2
{
public Super3()
{
System.out.println("with in super3()");
}
public void base1()
{
System.out.println("Base is called from super3");
}
}
---------Answer
with in super1()
with in super2()
Base is called from super2
with in super1()
with in super2()
with in super3()
Base is called from super3
Comments
Post a Comment