kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Cutting Fruit Mango
Cutting Fruit Apple
kodingwindow@kw:~$
Example 3: Java program for Abstract class
KW.java
abstractclassShape{abstractvoiddisplay();abstractvoidarea(floatb,floath);}classTriangleextendsShape{voiddisplay(){System.out.print("Area of Triangle ");}voidarea(floatb,floath){System.out.println((b*h)/2);}}classRectangleextendsShape{voiddisplay(){System.out.print("Area of Rectangle ");}voidarea(floatb,floath){System.out.println(b*h);}}classKW{KW(floata){System.out.println("Area of Square "+(a*a));}publicstaticvoidmain(String[]args){Trianglet=newTriangle();t.display();t.area(10,20);Rectangler=newRectangle();r.display();r.area(10,20);KWk=newKW(10);}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
Area of Triangle 100.0
Area of Rectangle 200.0
Area of Square 100.0
kodingwindow@kw:~$
Example 4: Java program for Abstract class
KW.java
abstractclassServer{Stringname;Server(Stringname){this.name=name;}publicabstractvoidstart();}classMongodbextendsServer{Mongodb(Stringname){super(name);}publicvoidstart(){System.out.println(this.name+" Started Successfully");}}classKW{publicstaticvoidmain(String[]args){Servers=newMongodb("MongoDB Server");s.start();}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
MongoDB Server Started Successfully
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.