override - I'm trying to implement DMD concept of java.But not getting the output as expected -


     class rectangle extends tri{        public void draw() {          system.out.println("rectangle");        }        }        class tri {       public void draw() {         system.out.println("triangle");        }      }      class circle extends rectangle{      public void draw() {       system.out.println("circle");       }      }      class rect     {      public static void main(string[] args)       {       circle c=new circle();       tri t=new tri();       rectangle r=new rectangle();         r.draw(); //rectangle       r=c;       r.draw();  //circle       t=r;       t.draw(); // rectangle expected.but getting circle output.        }      } 

in "t.draw" i'm giving reference "t=r", should display "rectangle" i'm getting output "circle".may because of earlier referencing r=c. still doubt.

you've assigned c variable r.

by time line t = r, r = c ... t = c.

why create variable t assign r , c it? why not deal r , c directly make things more clear?


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -