0% found this document useful (0 votes)
31 views2 pages

Understanding Abstract Classes in Java

An abstract class in programming is a restricted class that cannot be instantiated and must be inherited. It can contain abstract methods without a body, which must be implemented by subclasses. The document provides an example with a Fruit abstract class and an Apple subclass that implements the abstract method taste.

Uploaded by

logeshramesh9384
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Understanding Abstract Classes in Java

An abstract class in programming is a restricted class that cannot be instantiated and must be inherited. It can contain abstract methods without a body, which must be implemented by subclasses. The document provides an example with a Fruit abstract class and an Apple subclass that implements the abstract method taste.

Uploaded by

logeshramesh9384
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ABSTRACT CLASS:

Abstract class

The abstract keyword is a non-access modifier, used for classes and methods

Abstract class: is a restricted class that cannot be used to create objects (to access
it, it must be inherited from another class).

Abstract method: can only be used in an abstract class, and it does not have a
body. The body is provided by the subclass (inherited from).

abstract class Fruit {

// Abstract method (no body)

public abstract void taste();

// Regular method

public void color() {

[Link]("Fruits can have different colors");

class Apple extends Fruit

public void taste() {

[Link]("The apple tastes sweet and juicy");

}
class Main {

public static void main(String[] args) {

Apple myApple = new Apple(); // Create an Apple object

[Link](); // Output: The apple tastes sweet and juicy

[Link](); // Output: Fruits can have different colors

You might also like