implement abstract class in java code example
Example 1: java abstract class
abstract class Shape
{
abstract void sides();
}
class Triangle extends Shape
{
void sides()
{
System.out.println("Triangle shape has three sides.");
}
}
class Pentagon extends Shape
{
void sides()
{
System.out.println("Pentagon shape has five sides.");
}
public static void main(String[] args)
{
Triangle obj1 = new Triangle();
obj1.sides();
Pentagon obj2 = new Pentagon();
obj2.sides();
}
}
Example 2: how to create an abstract method in java
abstract class Scratch{
abstract public void hello();
abstract String randNum();
}
interface Other{
public void bye();
String randDouble();
}