• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object creation  RSS feed

 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,



out put :
Inside the A class!!
Inside the B class!!



Here in this code i suppose the object of class A is created first and then it is assigned with object of B. Am i going in the correct direction ??? help
and why

is not possible
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, its just object B being created. When object of B is being created, the constructor of the super class is executed.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinayak jog wrote:
and why
is not possible

A B is-an A (that's what the extends keyword means). An A is not necessarily a B. So you can't assign an A object to a B variable. The compiler will only allow things that it knows will work.
 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Your answer is correct, and thanks for the answer where i can find the documentation of this in sun java
i verified with following code


Inside the Z class!!
Inside the A class!!
Inside the B class!!


thank you so much


Thanks mathew
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find some tutorials at- http://download.oracle.com/javase/tutorial/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!