TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Sunday, 2 February 2020

java abstraction class | abstraction in java with realtime example

Java abstract Keyword

The abstract keyword is used to achieve abstraction in Java. It is a non-access modifier which is used to create abstract class and method.
The role of an abstract class is to contain abstract methods. However, it may also contain non-abstract methods. The method which is declared with abstract keyword and doesn't have any implementation is known as an abstract method.


java abstract class
Abstract class in java


Syntax:-  

     abstract class Employee  
{  
     abstract void work();  
}   

Rules of abstract keyword

Don'ts

  • An abstract keyword cannot be used with variables and constructors.
  • If a class is abstract, it cannot be instantiated.
  • If a method is abstract, it doesn't contain the body.

  • We cannot use the abstract keyword with the final.

  • We cannot declare abstract methods as private.


  • We cannot declare abstract methods as static.

  • An abstract method can't be synchronized.

Do's

  • An abstract keyword can only be used with class and method.
  • An abstract class can contain constructors and static methods.
  • If a class extends the abstract class, it must also implement at least one of the abstract method.
  • An abstract class can contain the main method and the final method.
  • An abstract class can contain overloaded abstract methods.
  • We can declare the local inner class as abstract.
  • We can declare the abstract method with a throw clause

Examples of abstract Keyword

    abstract class Vehicle  
{  
    abstract void bike();  
      
}  
     class Honda extends Vehicle  
{  
  
    @Override  
    void bike() {  
        System.out.println("Bike is running");  
      
    }  
      
}  
  
    public class AbstractExample1 {  
  
      public static void main(String[] args) {  
  
    Honda obj=new Honda();  
    obj.bike();  
    }         

Output:

Bike is running

No comments:

Post a Comment