Home Answers Viewqa Java-Beginners How to implement this superclass Person

 
 


aien
How to implement this superclass Person
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners

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 Pages:
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
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
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
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 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
The implement keyword
The implement keyword       In java programming language, the keyword implement specifies... for using the implement keyword in a class. public class DominoPizza
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
Implement the Serializable Interface
Implement the Serializable Interface  hii How many methods do u implement if implement the Serializable Interface?   hiii... to implement
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 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
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
implement core data iphone sdk
implement core data iphone sdk  How to implement core data in iPhone SDK? Please Help
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
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
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
Implement mechanisms which support loose coupling between clients and components
Implement mechanisms which support loose...; Implement mechanisms which support loose coupling between.... To understand how access beans solve the problem of performance degradation in client
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
Java question to implement polymorphism - Java Beginners
Java question to implement polymorphism  I have a question that i need to answer:- Using the principle of polymorphism provide implementation.... Subscription is the superclass for the Online Fax Subscription hierarchy. Trial, Basic
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
implement internationlism in Flemish ans Spanish using Sturts1.1
implement internationlism in Flemish ans Spanish using Sturts1.1  HI - we are using struts1.1, we have a requirement to implement internationlism in Flemish ans Spanish. Will this be supported in Struts1.1? How to resolve
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
Implement JavaScript with JSP
Implement JavaScript with JSP...;ClearAction.jsp"). In this step you will learn how to delete data from database... data code ("update.jsp"). In this step you will learn, how to modify
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
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
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
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
can anyone help me to implement strength of the password - Security
can anyone help me to implement strength of the password  hi.. i have to implement password strength detection algorithm. How can i use dictionary in linux system
Implement Java clients calling Web Services
Implement Java clients calling Web... the enterprise components Next    Implement Java... application demonstrates how to code a proxy file
Need to implement Paging and field based sorting in JSP Servlet - JSP-Servlet
Need to implement Paging and field based sorting in JSP Servlet  Hi, Can some one please guide me how we can implement the paging and field based sorting on records. Following is my requirement: Suppose we fetch the record
Implement an interface in a JSP
Implement an interface in a JSP  Can we implement an interface in a JSP?   
Where to implement spring - Spring
Where to implement spring   Hi, Where we implement spring framework in j2ee appplication. I mean which layer .Thanks
help to write a program for biology to know if two person are related or not
help to write a program for biology to know if two person are related or not   I wrote the program and i want some help pleas this program check between if they are related or not . i have no problem of reading file and inserted
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
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
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has following data members:- -name -account id -balance initialize the data members through constructors & define a print function & also define a function
Inheritance in Java with example
a superclass/parentclass to a subclass. Interface in java is used for class inheritance and interface inheritance. extend and implement keywords are used... cannot inherit members that are declared private in superclass. However
Implement array of objects
Implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
groupby implement in java
groupby implement in java  **import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays
groupby implement in java
groupby implement in java  **import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays
Can an Interface implement another Interface?
Can an Interface implement another Interface?   Hi, Can an Interface implement another Interface? Thanks
How GPS Works?
How GPS Works?       Introduction GPS or Global Positioning System is a technology for locating a person or an object in three dimensional space anywhere on the Earth
Java code to implement MULTIPATH INHERITANCE
Java code to implement MULTIPATH INHERITANCE  HI, I am new to java programming. I want to implement multipath inheritance in one java program... Please write code for above example to implement both
Method Overriding in Java
Method Overriding in Java means a Subclass uses extends keyword to override a super class method. In Overriding both subclass and superclass must have same parameters. Method Overriding in Java is used so that a subclass can implement
HTML5 form example, How to implement form tag in html document.
HTML5 form example, How to implement form tag in html document. HTML form tag is provides form to user. It support different controls. These controls is input controls, which is use for input user data. A HTML form always starts <

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.