The Artima Developer Community
Sponsored Link

Java Answers Forum
Help needed with inheritance!!

4 replies on 1 page. Most recent reply: Sep 22, 2003 8:34 PM by sandesh

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
sandesh

Posts: 10
Nickname: sandesh
Registered: Sep, 2003

Help needed with inheritance!! Posted: Sep 22, 2003 7:05 PM
Reply to this message Reply
Advertisement
hi,
i am new to java programming!! i was working with extended inheritance and found that i had some problem with passing parameters using superand get and set methods..

my program has three classes. student,person and a main class. i am trying to extend the person class to student and add some employee ID which is unique to student. i have a toString method in person class which prints out first and last name of the person. further, i am overriding this method with another tostring() in student. the problem is when i try to print out the student info using s.toString() in main method i am getting this output..
-----------------
student info
first namenull
Last name:null
student ID23
---------------------
whereas when i try to print out just the person info it prints out the names right..
could somebody put a sample code to demonstrate the same scenario..
thanks


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Help needed with inheritance!! Posted: Sep 22, 2003 8:22 PM
Reply to this message Reply
Post your code for student class please?

also when you overside the toString() method what you should do may be is to invoke the super.toString() method and add the Employee ID to that.

sandesh

Posts: 10
Nickname: sandesh
Registered: Sep, 2003

Re: Help needed with inheritance!! Posted: Sep 22, 2003 8:27 PM
Reply to this message Reply
thanks...
i made some mistake in the way i was passing the parameters..i got it right now. i can't put my code here since this is an assignment and i may be held for plagiarism..thats the reason why i didn't post my code..i will try to explain my problem better next time.
thanks

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Help needed with inheritance!! Posted: Sep 22, 2003 8:32 PM
Reply to this message Reply
You could mail me if you want to

sandesh

Posts: 10
Nickname: sandesh
Registered: Sep, 2003

Re: Help needed with inheritance!! Posted: Sep 22, 2003 8:34 PM
Reply to this message Reply
thats a good idea..will do that next time i have a problem

thanks

Flat View: This topic has 4 replies on 1 page
Topic: Mouse movement Previous Topic   Next Topic Topic: importing a package from a sibling directory

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use