Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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
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
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
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
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
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 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 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
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 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
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 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
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
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
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
implement core data iphone sdk
implement core data iphone sdk  How to implement core data in iPhone SDK? Please Help
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
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
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
Design and Implement GPA Calculator
Design and Implement GPA Calculator  Once the user clicks on the calculate button the program should display on a dialog box first the info about the student like his name. ID, session and student type. Second the program
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
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
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
Java code to implement MULTIPATH INHERITANCE
Java code to implement MULTIPATH INHERITANCE  Hi, I am new to java .so please write code for this inheritance example... Student | ----------- | | Test Sports
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
Implement Date Class
Implement Date Class The class Date represents a specific instant in time. It allowed the interpretation of dates as year, month, day, hour, minute... are going to implement Date Class. Here is the code: public class Date
What is an efficient way to implement a singleton pattern in Java?
What is an efficient way to implement a singleton pattern in Java?  What is an efficient way to implement a singleton pattern in Java
Implement Complex Number Class
Implement Complex Number Class You all are aware of Complex Numbers. These numbers consists of two parts,real and imaginary which can be written in the form... are going to implement Complex Number class and perform operations on it. Here
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
write a javascript progam to implement functions in html
write a javascript progam to implement functions in html  write a javascript progam to implement functions in html  Please visit the following link: http://www.roseindia.net/javascript/emailvalidation.shtml http
Advertisements
 

 

 

DMCA.com