class A //names of classes are simplified for better understanding
{
public void t1()
{
System.out.println("in t1 method...");
}
}
class B extends A
{
public void t2()
{
System.out.println("in t2 method....");
}
}
class C extends B
{
public void t3()
{
System.out.println("in t3 method....");
}
}
public class Streams { //upstream and down stream
public static void main(String [] args)
{
B rv1= new C();//upstram // (or) B rv1 = (B) new C();
rv1.t1(); // this is possible because there is
rv1.t2(); //only one super class for every subclass
A rv2 =(A) rv1; //upstream
rv2.t1();
B rv3=(B) rv2; //downstream
rv3.t1();
rv3.t2();
C rv4 = (C) rv3;//downstream
rv4.t1();
rv4.t2();
rv4.t3();
}
}
{
public void t1()
{
System.out.println("in t1 method...");
}
}
class B extends A
{
public void t2()
{
System.out.println("in t2 method....");
}
}
class C extends B
{
public void t3()
{
System.out.println("in t3 method....");
}
}
public class Streams { //upstream and down stream
public static void main(String [] args)
{
B rv1= new C();//upstram // (or) B rv1 = (B) new C();
rv1.t1(); // this is possible because there is
rv1.t2(); //only one super class for every subclass
A rv2 =(A) rv1; //upstream
rv2.t1();
B rv3=(B) rv2; //downstream
rv3.t1();
rv3.t2();
C rv4 = (C) rv3;//downstream
rv4.t1();
rv4.t2();
rv4.t3();
}
}
No comments:
Post a Comment