Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
676 views

Inheritance Assignment

1. Create a Person class with a name variable. Create an Employee class that inherits from Person with additional variables for annual salary, start year, and national insurance number. Include constructors and accessors. Create a TestEmployee class to test the Employee class. 2. Create an Animal class with eat() and sleep() methods. Create a Bird class that inherits from Animal and overrides the parent methods, adding a fly() method. Create instances of Animal and Bird to invoke their methods. 3. Create a Teacher class that inherits from Person with additional variables for salary and subject. Create a CollegeStudent class that inherits from Student and adds variables for year and major.

Uploaded by

sasirekha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
676 views

Inheritance Assignment

1. Create a Person class with a name variable. Create an Employee class that inherits from Person with additional variables for annual salary, start year, and national insurance number. Include constructors and accessors. Create a TestEmployee class to test the Employee class. 2. Create an Animal class with eat() and sleep() methods. Create a Bird class that inherits from Animal and overrides the parent methods, adding a fly() method. Create instances of Animal and Bird to invoke their methods. 3. Create a Teacher class that inherits from Person with additional variables for salary and subject. Create a CollegeStudent class that inherits from Student and adds variables for year and major.

Uploaded by

sasirekha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Inheritance Assignment

1.Create a class called Person with a member variable name. Save it in a file called
Person.java Create a class called Employee who will inherit the Person class. The other data
members of the employee class are annual salary (double), the year the employee started to
work, and the national insurance number which is a String. Save this in a file called
Employee.java Your class should have a reasonable number of constructors and accessor
methods. Write another class called TestEmployee, containing a main method to fully test
your class definition.

2. Create a class named ‘Animal’ which includes methods like eat() and sleep(). Create a child
class of Animal named ‘Bird’ and override the parent class methods. Add a new method
named fly(). Create an instance of Animal class and invoke the eat and sleep methods using
this object. Create an instance of Bird class and invoke the eat, sleep and fly methods using
this object.

3. A HighSchool application has two classes: the Person superclass and the Student subclass.
Using inheritance, in this lab you will create two new classes, Teacher and CollegeStudent. A
Teacher will be like Person but will have additional properties such as salary (the amount the
teacher earns) and subject (e.g. “Computer Science”, “Chemistry”, “English”, “Other”). The
CollegeStudent class will extend the Student class by adding a year (current level in college)
and major (e.g. “Electrical Engineering”, “Communications”, “Undeclared”)

(Solutions not available)

You might also like