How to implement this superclass Person

How to implement this superclass Person

View Answers

September 7, 2009 at 5:24 PM

Hi Friend,

Try the following code:

class Person{
private int year;
private String name;
public Person(String name,int year){
year=year;
name=name;
}
}
class Student extends Person{
private String major;
public Student(String name,int year,String major){
super(name,year);
major=major;
}
}
class Instructor extends Person{
private int salary;
public Instructor(String name,int year,int salary){
super(name,year);
salary=salary;
}
}
public class PersonTester
{
public static void main(String[] args)
{
Person p = new Person("Perry", 1959);
Student s = new Student("Sylvia", 1979, "Computer Science");
Instructor e = new Instructor("Edgar", 1969, 65000);
System.out.println(p);
System.out.println("Expected: Person[name=Perry,birthYear=1959]");
System.out.println(s);
System.out.println("Expected: Student[super=Person[name=Sylvia,birthYear=1979],major=Computer Science]");
System.out.println(e);
System.out.println("Expected: Instructor[super=Person[name=Edgar,birthYear=1969],salary=65000.0]");
}
}

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
How to implement a superclass Person? - Java Beginners
How to implement a superclass Person?  How to implement a superclass Person. Make two classes, Student and Lecturer, that inherit from Person... to implement the class..and how to write the toString method? please help me...  
How to implement this superclass Person - Java Beginners
How to implement this superclass Person  how to Implement a superclass Person which it need to Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major
Advertisements
ModuleNotFoundError: No module named 'superClass'
'superClass' How to remove the ModuleNotFoundError: No module named 'superClass' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'superClass'  Hi, My Python
ModuleNotFoundError: No module named 'superClass'
'superClass' How to remove the ModuleNotFoundError: No module named 'superClass' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'superClass'  Hi, My Python
how to implement spring security - Spring
how to implement spring security  Hai, iam working on small login application using hibernate on Spring. I wanted to implement spring security for my login application. Can any one tell me what is SpringSecurity, and how
How to implement FTP using java
How to implement FTP using java  Hi, I am a B.tech student and I want to implement FTP using Java to transfer files and exchange files between FTP client and FTP server. Could anyone help me for How to implement FTP using java
what is a thread initial state? how to implement it?
what is a thread initial state? how to implement it?  what is a thread initial state? how to implement
JAVA CLASSES/ SUPERCLASS
a subclass of Employee. A person has a name, address, phone number, and email address... an object of class contractWorker and show how this object inherits behavior defined in superclass worker
How to implement openId java web based application?
How to implement openId java web based application?  In my web application i want to implement the OpenId just like stackoverflow.com have to login.... Please tell me how to implement it in java web application in details
how to implement ajax in struts2 to operate on selectbox in jsp
how to implement ajax in struts2 to operate on selectbox in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes like </s:form>` ` now i want that when i select a district
How to implement session variables - JSP-Servlet
How to implement session variables  Hi, I have a servlet which gets..._num in the Jsp page (y). How should i do it? I'm trying using... print it. Do I need to add any path like (@servlet) because how the jsp know
what is cloud computing? any how we can implement?
what is cloud computing? any how we can implement?  what is cloud computing? any how we can implement
How to implement xml parsing in iphone ? -RV
How to implement xml parsing in iphone ? -RV  In .h file @interface RootViewController : UITableViewController<NSXMLParserDelegate>{ IBOutlet UITableView *page1; NSMutableArray *titlearray
how to implement Single Sign On in enterprise application using spring framework
how to implement Single Sign On in enterprise application using spring framework  how i can implement the single sign on in my spring based web app..i am new to spring frame work..any help will be appreciated as its urgent
How to implement link in Web app lead to report with print and save features
How to implement link in Web app lead to report with print and save features   Hi friends, I developed a web application based on Java MVC architecture and Struts framework with Tomcat appserv, and I need to implement link lead
How to implement Captcha in PHP Form using GD Library
How to implement Captcha in PHP Form using GD Library  Hi, How to show Captcha in PHP Form. So, please suggest any online reference so that i will try myself. Thanks, (adsbygoogle = window.adsbygoogle || []).push
ModuleNotFoundError: No module named 'person'
'person' How to remove the ModuleNotFoundError: No module named 'person'...ModuleNotFoundError: No module named 'person'  Hi, My Python... to install padas library. You can install person python with following command
Implement push
Implement push  Hi.. How do you implement push on a flex applications? give me answer with example so i clearly understand Thanks  Ans: push implement on a flex applications using BlazeDS Server
How to implement ajax in struts2 to operate on select box in jsp
How to implement ajax in struts2 to operate on select box in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes like <s:form action=""> <s:select id="d" name="dist" onchange
How can we implement Pop-up in JQuery without Plugin?
How can we implement Pop-up in JQuery without Plugin?  Hi Sir How can we Implement pop-up in JQuery without using plug-in. Please provide me code with detailed answer. Thanks in advance.   Hello Friend You need
Implement push
Implement push  hi....... just tell me about How do you implement push with flex data services? give me answer with example Thanks  Ans: Using BlazeDS Server and Live Cycle Data Services
How can i implement the calculator programe in jsp code
How can i implement the calculator programe in jsp code  Please send code for the calculator using jsp technologies please guidelines to me.   Here is a simple jsp calculator code that accepts two numbers from the user
doubt about superclass reference and subclass object
doubt about superclass reference and subclass object  class superclass { p.bark() } class subclass extends superclass { p.bark } {p.s.v.m() superclass refvar = new subclass(); p.bark(); } Now my questions 1.Why is necessary
The implement keyword
The implement keyword       In java programming language, the keyword implement specifies... for using the implement keyword in a class.ADS_TO_REPLACE_1 public class
Implement the Serializable Interface
Implement the Serializable Interface  hii How many methods do u implement if implement the Serializable Interface?   hiii,ADS_TO_REPLACE_1... of its own to implement
ModuleNotFoundError: No module named 'cubicweb-person'
named 'cubicweb-person' How to remove the ModuleNotFoundError: No module named 'cubicweb-person' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'cubicweb-person'  Hi, My
ModuleNotFoundError: No module named 'cubicweb-person'
named 'cubicweb-person' How to remove the ModuleNotFoundError: No module named 'cubicweb-person' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'cubicweb-person'  Hi, My
ModuleNotFoundError: No module named 'person-extractor'
named 'person-extractor' How to remove the ModuleNotFoundError: No module named 'person-extractor' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'person-extractor'  Hi, My
ModuleNotFoundError: No module named 'person-tracking'
named 'person-tracking' How to remove the ModuleNotFoundError: No module named 'person-tracking' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'person-tracking'  Hi, My
ModuleNotFoundError: No module named 'cubicweb-person'
named 'cubicweb-person' How to remove the ModuleNotFoundError: No module named 'cubicweb-person' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'cubicweb-person'  Hi, My
org.apereo.cas - cas-server-support-person-directory version 6.1.0-RC4 Maven dependency. How to use cas-server-support-person-directory version 6.1.0-RC4 in pom.xml?
org.apereo.cas  - Version 6.1.0-RC4 of cas-server-support-person-directory Maven dependency? How to use  org.apereo.cas  - Version 6.1.0-RC4 of cas-server-support-person-directory in pom.xml? How to use cas-server-support
org.apereo.cas - cas-server-support-person-directory version 5.3.14 Maven dependency. How to use cas-server-support-person-directory version 5.3.14 in pom.xml?
org.apereo.cas  - Version 5.3.14 of cas-server-support-person-directory Maven dependency? How to use  org.apereo.cas  - Version 5.3.14 of cas-server-support-person-directory in pom.xml? How to use cas-server-support-person
org.apereo.cas - cas-server-support-person-directory version 5.2.6 Maven dependency. How to use cas-server-support-person-directory version 5.2.6 in pom.xml?
org.apereo.cas  - Version 5.2.6 of cas-server-support-person-directory Maven dependency? How to use  org.apereo.cas  - Version 5.2.6 of cas-server-support-person-directory in pom.xml? How to use cas-server-support-person
org.apereo.cas - cas-server-support-person-directory version 5.2.6 Maven dependency. How to use cas-server-support-person-directory version 5.2.6 in pom.xml?
org.apereo.cas  - Version 5.2.6 of cas-server-support-person-directory Maven dependency? How to use  org.apereo.cas  - Version 5.2.6 of cas-server-support-person-directory in pom.xml? How to use cas-server-support-person
org.apereo.cas - cas-server-support-person-directory version 6.1.0-RC5 Maven dependency. How to use cas-server-support-person-directory version 6.1.0-RC5 in pom.xml?
org.apereo.cas  - Version 6.1.0-RC5 of cas-server-support-person-directory Maven dependency? How to use  org.apereo.cas  - Version 6.1.0-RC5 of cas-server-support-person-directory in pom.xml? How to use cas-server-support
org.apereo.cas - cas-server-support-person-directory version 5.3.8 Maven dependency. How to use cas-server-support-person-directory version 5.3.8 in pom.xml?
org.apereo.cas  - Version 5.3.8 of cas-server-support-person-directory Maven dependency? How to use  org.apereo.cas  - Version 5.3.8 of cas-server-support-person-directory in pom.xml? How to use cas-server-support-person
Implement the Queue in Java
Implement the Queue in Java       In this section, you will learn how to implement the queue. A queue holds a collection of data or elements and follows the FIFO ( First In First
implement microsoft office
implement microsoft office   how implement microsoft office in my java swing project ,or when microsoft office is not install then file open in defualt text editar.please send me source code
implement core data iphone sdk
implement core data iphone sdk  How to implement core data in iPhone SDK? Please Help
Implement Drag and drop
Implement Drag and drop  Hi...... Please give the answer with example How do you implement drag and drop on components that do not support ondrag and ondrop? Thanks in advance   Ans: The example
ModuleNotFoundError: No module named 'random-italian-person'
: No module named 'random-italian-person' How to remove the ModuleNotFoundError: No module named 'random-italian-person' error? Thanks   Hi...ModuleNotFoundError: No module named 'random-italian-person'  Hi
ModuleNotFoundError: No module named 'dedupe-variable-person'
: No module named 'dedupe-variable-person' How to remove the ModuleNotFoundError: No module named 'dedupe-variable-person' error? Thanks   Hi...ModuleNotFoundError: No module named 'dedupe-variable-person'  Hi
Implement an interface in a JSP
Implement an interface in a JSP  Can we implement an interface in a JSP?   
Implement transaction serializability
Implement transaction serializability  I need to implement transaction serializability in Java using semaphores/monnitors. What is the code to do
How to Implement ERP?
Where to implement spring - Spring
Where to implement spring   Hi, Where we implement spring framework in j2ee appplication. I mean which layer .Thanks
Person have name field of Name type..??
, middlename, and lastname but i dont know how to use this class in person to give him name? can you please write code two two different class and show me how to use...Person have name field of Name type..??  Person have name field
implement sale purchaes
implement sale purchaes  i want to implement a code in advance java with connectivity .. i have a table in database in which i have some stack of sms if customer puchases and enter value in text box the amount will be deduct
referring to question Person.. - Java Beginners
referring to question Person..  Hi!firstly i want to thank to someone who always answer my questions, i really appreciate it..emm may i know what...=gender; this is base on previous question (Person)..can u explain to me
java: implement a class queue
java: implement a class queue  Implement a class Queue which supports the following operations: boolean isEmpty() Returns true if the queue is empty, and false otherwise. int peak() Returns the value at the front of a non

Ads