• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program on OOP  RSS feed

 
ramap prabhas
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell me how this program works.

Edited by Corey McGlone: Added CODE Tags
[ March 17, 2004: Message edited by: Corey McGlone ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this thread to Java in General (Beginner)
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Homework problem, eh?
When you specify the type of an object in your code, certain things are solved polymorphically during program execution, and others are decided at compile time.
In your case, x.s1 will return "D" since x is typed as a D class.
When you invoke x.getS1(), it determines which function runs polymorphically at runetime. x is actually a E object, so it invokes the method with the getS1 method defined in the class E -- which of course uses its overriden value of s1 which is "E".
The moral of the story:
1) class member variables are resolved at compile time.
2) class member functions are resolved at runtime.
That clear anything up for you?
 
ramap prabhas
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathaniel . I got it.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For further assistance in your journey to understand polymorphism, take a look at the JavaRanch Campfire story title, "How my Dog learned Polymorphism."
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!