









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










public class Animal { public Animal(String aType) { type = new String(aType); } public String toString() { return โThis is a โ + type; } private String type; }
public class Dog extends Animal { public Dog(String aName) { super(โDogโ); name = aName; breed = โUnknownโ; } public Dog(String aName, String aBreed) { super(โDogโ); name = aName; breed = aBreed; } private String name; private String breed; }
23 ๏ Overloading deals with multiple methods in the same class with the same name but different signatures ๏ Overloading lets you define a similar operation in different ways for different data ๏ Overriding deals with two methods, one in a parent class and one in a child class, that have the same signature ๏ Overriding lets you define a similar operation in different ways for different object types
26 ๏ A class called Object is defined in the java.lang package of the Java standard class library ๏ All classes are derived from the Object class ๏ even if a class is not explicitly defined to be the child of an existing class, it is assumed to be the child of the Object class ๏ the Object class is therefore the ultimate root of all class hierarchies ๏ The Object class contains a few useful methods, which are inherited by all classes ๏ toString() ๏ equals() ๏ clone()
The Object Class: the equals Method
EXAMPLE class Animal { private String type; public Animal(String aType) { type = new String(aType); } public void eat() { System.out.println("Animal eat"); } }