























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!
























TOPIC 6: Abstraction in Java : Abstract Class and Interface
ctto:Afsara Tasneem Misha Department of CSEDaffodil International University
access-specifier abstract return-type method_name();
public abstract void printStatus();
An abstract class that has abstract and non-abstract methods
13
public class Car extends Vehicle { public void move() { System.out.println("Car moves faster."); } public static void main(String[] args) { Car c1 = new Car(); c1.move(); c1.carry(); } } // Outputs: Car moves faster. All Vehicle carry loads
public abstract class Vehicle { public abstract void move(); public void carry() { System.out.println("All Vehicle carry loads"); } }
An abstract class that has abstract , non-abstract methods and Constructor
public class Car extends Vehicle { public void move() { System.out.println("Car moves faster."); } public static void main(String[] args) { Car c1 = new Car(); c1.move(); c1.carry(); } } // Outputs: Vehicle is Created. Car moves faster.All Vehicle carry loads
public abstract class Vehicle { public Vehicle() { System.out.println("Vehicle is Created."); } public abstract void move(); public void carry() { System.out.println("All Vehicle carry loads"); } }
Vehicle
Car
Boat
Animal
_+ eat() : void
Human
Example โ 5 :
Home Work
Lion
Bird
Main
+main(String [] ) : void