Bookmark Topic Watch Topic
  • New Topic

difference in the instance  RSS feed

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
Basing on my erlier question posted,very simple question

I have 2 classes

class Parent{ Parent(){ System.out.println("Parent Constructor"); } void move(){ System.out.println("Parnet Move"); } }

class Child extends Parent{Child(){System.out.println("Child Constructor");} void run(){System.out.println("child run");}}



public class Test {


public static void main(String[] args) {
Parent p = new Child();
Child c = new Child();

//what is the difference between these 2 below statements

p.move();

c.move();

}}

What happens internally when I use parent reference which holds child object and child reference for holding the hcild object here?

Please thsi is very simple question but still I have some problem to understand the differences



Thanks
Sai
--------------------
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Don't reopen a new thread. I see there is a difference between the other one (move instead of run), but it is still basically the same question.

If you go to the Java in General (beginner) forum you will find your old thread. Just continue there.

And while you're at it, search (Google, Wikipedia) a bit about polymorphism.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!