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{ }
for example
abstract int mymetod();
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
Suggested for you
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…