Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

All other information the code is shown but it is not show only General Information?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Output of the given code
UserInformation [aboutMe=software engineer, relationshipStatus=single, contact=ContactInformation [contactId=123, address=Address [address1=123 shiv bajar, address2=shiv shakti colony, city=Tikamgarh, pin=472001], email=AkashBhamri741@gmail.com, phoneNo=12435, mobileNo=851702833402, residenceNo=233]]

Address.java

ContactInfomation.java




Generalinformation.java


UserInformation.java

UserDemo.java

 
Saloon Keeper
Posts: 8598
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UserInformation extends GeneralInformation. GeneralInformation has a toString() method but so does UserInformation which hides the one in GeneralInformation.
 
Akash bhamri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@CareyBrown didn't get your point? what do I have to do to show the info of generalInformation?
 
Carey Brown
Saloon Keeper
Posts: 8598
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In UserInformation.toString() call super.toString() and then append the stuff you currently have in UserInformation.toString().

When one class extends another class and they both have a method of the same name and signature, such as toString(), the sub-class's toString() will get called instead of the super-class's IF you've given it a sub-class object to operate on.

GeneralInformation is your super-class
UserInformation is your sub-class

You construct a UserInformation object - so therefore the UserInformation.toString() is the one that gets called instead of the super class's toString(). If you ALSO want to call the super-class's toString() method you have to do that explicitly with super.toString() which returns a String.
 
Akash bhamri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanxx bro got your point but where do I have to write super.toString() so that I call both the method which are in super and subclass?
 
Akash bhamri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the super method inside the toString method which is present in the user information is it correct?
 
Marshal
Posts: 74069
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please show us what the code looks like now.
 
Akash bhamri
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing happen I was got the same output but carey was right because when I comment tostring method which was in user information then It show tostring method which was in general information or vise versa..
 
Campbell Ritchie
Marshal
Posts: 74069
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Two hours ago, I wrote:Please show us what the code looks like now.

That still applies.
 
Carey Brown
Saloon Keeper
Posts: 8598
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From UserInformation...

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic