Get startedGet started for free

Creating abstract classes

For people who love cars, hearing the horn is all they need to identify a particular type of car. Many car manufacturers know this and make their cars sound unique as a branding strategy. You will update the Car class to contain a method for the horn functionality of cars.

NOTE: An abstract class cannot have instance objects created from it as it exists to be merely a blueprint from which to be inherited.

This exercise is part of the course

Introduction to Object-Oriented Programming in Java

View Course

Exercise instructions

  • Make the Car class an Abstract class using the abstract keyword.
  • Create a public abstract void method inside Car called soundHorn.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

public class Main {  

	// Make Car abstract
    static ___ class Car {

        public Car() {

        }

        // Create soundHorn abstract method
        ___ ___ ___ ____;

    }
    
    public static void main(String[] args) {        
                       
    }
    
}
Edit and Run Code