Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • ACHIEVING ABSTRACTION BY ABSTRACT CLASS IN JAVA

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 411
    Comment on it

    Abstraction

    Abstraction is a concept which shows only important(essential) feature and hide background details. In other way, abstraction shows only those things to user which are important and hides the background details. for eg :- example of abstraction is tv remote, we press its button and see that channel get change, but we did not its internal processing.

    we achieve abstraction in java by :-

    • Abstract class
    • Interface

    ABSTRACT CLASS

    we use abstract keyword for defining abstract class. That means a class which contain abstract keyword is a abstract class.

    syntax

        abstract class A{} 
    
    example :-
    
    abstract class Print{  
    abstract void draw();  
    }  
            //In real scenario, implementation is provided by others i.e. unknown by end user  
    class A extends Print{  
    void draw(){System.out.println("A class implementing method of Print class");}  
    }  
    
    class B extends Print{  
    void draw(){System.out.println("B class implementing method of Print class");}  
    }  
    
                 //In real scenario, method is called by programmer or user  
    class Abstraction{  
    public static void main(String args[]){  
    Print s=new B();//In real scenario, object is provided through method e.g. getShape() method  
    s.draw();  
    }  
    }  
    

    OUTPUT

    B class implementing method of Print class
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: