Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Superclass Constructor

 
karl czukoski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given:


prints: b h hn x

Can someone explain why the first constructor Building() of the superclass Building is called instead of the second constructor Building(String name) ?
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After I fixed the compiler error, it does not print b h hn x . It prints:
b h
bn x
I think you are running old code.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ karl
welcome to the javaranch family

please QuoteYourSources
 
karl czukoski
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Prasad

So correct me if wrong but I think the first constructor Building() of the superclass Building is used b/c the compiler looks for the no-arg constructor (basing this logic off of question 2 pg. 172 explanation).
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
QuoteYourSources means please provide the source from where you got this question
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic