• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Java Abstraction

by admin

An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon): abstract void walk();. The user will have the information on what the object does instead of how it does it.

Abstract Class

  • Abstraction is achieved using abstract classes and interfaces.
  • To use an abstract class, you have to inherit it from another class.
  • Any class that contains an abstract method should be defined as abstract.

A class containing an abstract method is an abstract class.

we can define our Animal class as abstract just like concrete class in the following way:

abstract class Animal {
  int legs = 0;
  abstract void makeSound();
}

Output

class Cat extends Animal {
  public void makeSound() {
    System.out.println("Meow");
  }
}

This is used when there is no meaningful definition for the method in the superclass.

Filed Under: Java

Some more articles you might also be interested in …

  1. Using ‘abstract’ Keyword in Java
  2. Java Methods
  3. Exception Handling in Java
  4. JavaFX ComboBox: Set a value to the combo box
  5. Java Variable Types
  6. Java Overriding
  7. Java Polymorphism
  8. Java Classes and Objects
  9. Using ‘final’ Keyword in Java
  10. Introduction to Java Packages

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright