Chapter 5
Chapter 5
Chapter 5
Abstract Class
1. Abstract Class
2. Abstract Method
3. Example “Creating Abstract Superclass: Employee class”
4. Extending Concrete Classes
5. Implementing an Abstract Method
Contents
Recommended Reading
1. Java Abstract Classes
https://www.w3schools.com/java/java_abstract.asp
• Abstract Class
Abstract Class
• Sometimes, it does NOT make sense to create objects from specific
classes.
• An abstract class can only be used to derive other classes; you cannot
create objects from an abstract class
8-6
Abstract Method
• It has no method body and ends with a semicolon in place of its body.
public abstract long getSerNumber();
• An abstract class can have any number of abstract and/or fully defined
methods.
}
Example
// three-argument constructor
public Employee(String first, String last, String ssn ) {
firstName = first;
lastName = last;
socialSecurityNumber = ssn;
} // end three-argument Employee constructor
Abstract Class Employee: Outline (Cont’d)
public class Cat extends Animal { public class Cow extends Animal {
public Cat() { public Cow() {
kind = "cat"; kind = "cow";
} }
public String speak() { public String speak() {
return "meow"; return "moo";
} }
} }
Thank You