Abstract Class with Mixed Methods in Java


Write a Java program to demonstrate an abstract class having both abstract and non-abstract methods

  • There's an abstract class Vehicle with a concrete method start() and an abstract method stop().
  • Car is a concrete class that extends Vehicle and provides an implementation for the stop() method.
  • In the Main class, an instance of Car is created.
  • The start() method of Vehicle is called on the Car instance, which prints "Starting vehicle...".
  • Then, the stop() method of Car is called, which prints "Stopping car...".

Source Code

abstract class Vehicle
{
	void start()
	{
		System.out.println("Starting vehicle...");
	}
 
	abstract void stop();
}
 
class Car extends Vehicle
{
	@Override
	void stop()
	{
		System.out.println("Stopping car...");
	}
}
 
public class Main
{
	public static void main(String[] args)
	{
		Car car = new Car();
		car.start();
		car.stop();
	}
}

Output

Starting vehicle...
Stopping car...