- 1

Write single program covering all oops concepts class, object, encapsulation, polymorphism, inheritance and encapsulation

not sample program write real time program like ATM bank etc

15th Dec 2016, 11:08 AM
Ansar ali
Ansar ali - avatar
3 Antworten
+ 15
Inheritance, polymorphism, abstraction, encapsulation,over riding, over loading all implemented in single program. The file name must be MainClass.java Program: class One { public void display() { System.out.println("One"); } } //inheritance class Two extends One { @Override public void display() { System.out.println("Two"); } public int add(int x, int y) { return x+y; } //Overload public double add(double x,double y) { return x+y; } } //encapsulation example class EncapTest { private String name; public String getName() { return name; } public void setName(String newName) { name = newName; } } //abstraction abstract class TwoWheeler { public abstract void run(); } class Honda extends TwoWheeler{ public void run(){ System.out.println("\nbike is Running.."); } } class MainClass { public static void main(String[] args) { One a=new One(); a.display(); Two b=new Two(); b.display(); System.out.println(b.add(4,2)); System.out.println(b.add(5.,2.)); //polymorphism EncapTest encap = new EncapTest(); encap.setName("Sandeep's"); System.out.print("Name : " + encap.getName() ); TwoWheeler test = new Honda(); test.run(); } } Output: One Two 6 7.0 Name : Sandeep's bike is Running.
16th Jan 2018, 1:37 PM
Shreyas Desai
Shreyas Desai - avatar
+ 1
Check my Visitor pattern code.
4th Jan 2017, 4:22 PM
Abhilash Kumar Vedwan
Abhilash Kumar Vedwan - avatar
0
i want to understand how class is work?
12th Jun 2019, 12:05 AM
Medard Turatsinze
Medard Turatsinze - avatar