keyword

The abstract keyword in Java language

The abstract keyword in Java language

Here, we learn about The abstract keyword in Java language.

The abstract is a keyword in Java programming language. it can be applied to class and methods

when a class is declared as abstract it called as the abstract class.  In other words, if a class has any abstract methods, the entire class must be declared as abstract.

       for example

             abstract class My_class{

                    }
  • The keyword abstract in Java can be used for method(called as the abstract method) declaration.

          for example

                        abstract int mymetod();

  • When a class is declared as abstract, it cannot be instantiated.
  • When a method is declared as abstract, it is known as the abstract method. This does not have any implementation. The abstract method declaration must be ended with a semicolon.
  • Abstract classes must have one or more abstract methods. However, the abstract class does not necessarily require all its methods to be abstract.

Syntax

the syntax of the abstract class given below

//declare a abstract class
abstract  class my_class{
//class properties
}

 

 

When a class is declared abstract, then its methods may also be declared abstract.

the syntax of the abstract method given below

//diclare a abstract method
abstract my_Method (list_of_parameters);

 

When a method is declared abstract, the method does not have a definition and ends with a semicolon.

Example

abstract class My_Class{ //class diclared as abstract
abstract void my_Method();//abstract method inside the class
void method_One(){        //non abstract method with implementation
  System.out.println("This is a non abstract method");
}
}
class Second_Class extends My_Class{
    void my_Method(){
    System.out.println("Implementation of abstract method");
}

}

class Test_Class2{
public static void main(String[] args){
    My_Class obj=new Second_Class();
    obj.my_Method();
    obj.method_One();
    
}
    
}

 

When the above code is executed, it produces the following results

implementation of abstract method
This is a non abstract method

 

There are other Java language keywords that are similar to this keyword

 byte  in Java Language

 int  in Java Language

long  in Java Language

 float  in Java Language

char  in Java Language

 void  in Java Language

try  in Java Language

Catch in Java Language

implements  in java Language

public  in Java Language

static  in Java language

Volatile  in Java Language

Package  in Java Language

class  in Java Language

boolean  in Java Language

break in Java Language

do  in Java Language

double  in Java Language

This  in Java Language

final  in Java Language

switch  in Java Language

interface  in Java Language

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Finally  in Java language

The break keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago