Google Search

Saturday, October 24, 2015

What is abstract class? Explain need of abstract class with example.

Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods. Let's look at an example of an abstract class, and an abstract method.
abstract class Bike{ 
abstract void run();
}
class Honda extends Bike{
void run(){System.out.println("Honda is a good bike..");}
public static void main(String args[]){
Bike obj = new Honda();
obj.run();
}
}

No comments:

Post a Comment