hw11 - instance ±elds Note all of the instance ±elds of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 302 Homework 11 - Not Due Name: 1. Suppose that there is a class named Ship and subclasses Yacht and CruiseShip which extend Ship . Assume all have default constructors. Write code to: (a) Create a CruiseShip object and store it in a variable of type Ship . (b) Create a Ship object and store it in a variable of type Yacht . 2. Suppose that there is a class named Pet with a constructor that takes in the age and name of the pet, in that order, as parameters. You decide to write a Dog subclass with the Pet class as it’s parent. Fill in the contents of the constructor of the Dog class; you must initialize all
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: instance ±elds. Note: all of the instance ±elds of the Pet class are private . public class Dog extends Pet { private String breed; public Dog(int theAge, String theName, String theBreed) { } } 3. Given these three classes and their speci±ed methods: • SecurityGuard : getName() , getSalary() , secureBuilding() , takeBreak() • Secretary : getName() , getSalary() , takeBreak() • Baker : getName() , getSalary() , bakeBread() , decorateCake() write an inheritance diagram that maximizes code reuse. (Hint: create an Employee class ±rst)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online