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

Abstract Class in JAVA

An abstract class in Java is a class that cannot be instantiated directly but must be subclassed by another class. It can contain both abstract and non-abstract methods. Abstract classes are declared using the "abstract" keyword. The document provides an example of an abstract Bank class with an abstract interest() method that is overridden in subclasses TMB and SBI.

Uploaded by

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

Abstract Class in JAVA

An abstract class in Java is a class that cannot be instantiated directly but must be subclassed by another class. It can contain both abstract and non-abstract methods. Abstract classes are declared using the "abstract" keyword. The document provides an example of an abstract Bank class with an abstract interest() method that is overridden in subclasses TMB and SBI.

Uploaded by

Surya Dharshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Unit III - Abstract class in JAVA

Abstract class in Java


Java abstract class is a class that cannot be initiated by itself, it needs to be sub classed
by another class to use its properties. An abstract class is declared using the “abstract”
keyword in its class definition.
A class which is declared with the abstract keyword is known as an abstract class
in Java. It can have abstract and non-abstract methods (method with the body).

Ways to achieve Abstraction


There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface (100%)

Example for abstract class and method


package Examples;
abstract class Bank // bank abstract class
{
abstract void interest( ); // abstract method
public void output( ) // non abstract method / concrete method
{
System.out.println("Abstract method");
}
}
class TMB extends Bank // inherit the abstract class bank
{
void interest( ) // override
{
System.out.println("TMB interest is 10%");
}
}

class SBI extends Bank // inherit the abstract class bank


{
void interest( ) // override
{
System.out.println("SMB interest is 15%");
}
}

class Result
{
public static void main(String []arg)
{
Bank obj1=new TMB( );
obj1.output( );
obj1.interest( );
Bank obj2=new SBI( );
obj2.interest( ) ;
}
}

Output
Abstract method
TMB interest is 10%
SBI interest is 15%

You might also like