Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Abstraction in java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 280
    Comment on it

    Abstraction is defined as the hiding of backend content/details and only providing necessary information.
    There are two ways to achieve abstraction:-

    • Abstract class
    • Interface


    ABSTRACT CLASS:- The class which is declared as abstract is known as abstract class.The method of abstract class is implemented further.
    e.g of abstract class:

    abstract class area{
    abstract void rectangle(double x, double y);
    }
    class findarea extends area{
    void rectangle(double x, double y)
    {
    double ar=x*y;
    system.out.println("Area of rectangle-" +area);
    }
    class ar{
    public static void main(string args[])
    {
    double x,y;
    area ar= new area();
    system.out.print("enter length and breadth of rectangle-");
    x=get.nextDouble();
    y=get.nextDouble();
    area.rectangle(x,y);

    output- "enter length and breadth of rectangle-"

    INTERFACE:-An interface is a way for achieving fully abstraction and multiple inheritance.
    e.g of interface is:

    interface  Area
    {
    double compute(double x,double y);
    
    }
    class Rect implements Area
    {
    public double compute(double x,double y)
    {
    return x*y;
    }
    }
    
    
    class findarea
    {
    public static void main(String arg[])
    {
    Area A;
    Rect r=new Rect();
    A=r;
    System.out.println(The Area of rectangle is:+A.compute(30,20));
    }
    }

    output- " The area of rectangle is-600"

 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: