Vous êtes sur la page 1sur 5

//example of method overloading class room { double l,b; room(double x, double y) { l=x; b=y; } room(double x) { l=x; b=x; } double

area() { return (l*b); } } class roomarea2 { public static void main(String args[]) { room r1=new room(10.0,10.0); room r2=new room(11.0); double a1=r1.area(); double a2=r2.area(); System.out.println("Area1 = "+a1); System.out.println("Area2 = "+a2); } }//END OF PROGRAM //example of single inheritance class room { int l,b; room(int x, int y) { l=x; b=y; } int area() { return (l*b); } } class bedroom extends room { int h; bedroom(int x, int y, int z) { super(x,y); h=z; } int volume() { return (l*b*h); } } class inhertest

{ public static void main(String args[]) { bedroom r=new bedroom(14,12,10); int a=r.area(); int v=r.volume(); System.out.println("Area of bedroom = "+a); System.out.println("Volume of bedroom = "+v); } }//END //example of multilevel inheritance class room { int l,b; room(int x, int y) { l=x; b=y; } int area() { return (l*b); } } class bedroom extends room { int h; bedroom(int x, int y, int z) { super(x,y); h=z; } int volume() { return (l*b*h); } } class drawingroom extends bedroom { int m; drawingroom(int x, int y, int z, int a) { super(x,y,z); m=a; } int varea() { return (l*b*h*m); } } class inhertest1 { public static void main(String args[]) { drawingroom r=new drawingroom(14,12,10,10); int a=r.area(); int v=r.volume();

int c=r.varea(); System.out.println("Area of bedroom = "+a); System.out.println("Volume of bedroom = "+v); System.out.println("Area Volume of drawingroom = "+c); } }//END //example of hierarchical inheritance class room { int l,b; room(int x, int y) { l=x; b=y; } int area() { return (l*b); } } class bedroom extends room { int h; bedroom(int x, int y, int z) { super(x,y); h=z; } int volume() { return (l*b*h); } } class hall extends room { int m; hall(int x, int y, int z) { super(x,y); m=z; } int area1() { return (l*b*m); } } class hinhertest { public static void main(String args[]) { bedroom r=new bedroom(14,12,10); hall h=new hall(11,11,10); int a=r.area(); int v=r.volume(); int c=h.area1(); System.out.println("Area of bedroom = "+a); System.out.println("Volume of bedroom = "+v); System.out.println("Area of hall = "+c); }

}//END //example of overriding methods class super1 { int x; super1(int x) { this.x=x; } void display() { System.out.println("Super x is = "+x); } } class sub1 extends super1 { int y; sub1(int x, int y) { super(x); this.y=y; } void display() { System.out.println("Super value of x is = "+x); System.out.println("Sub value of y is = "+y); } } class overridetest { public static void main(String args[]) { sub1 s=new sub1(11,11); s.display(); } }//END //example of abstract (class & methods) abstract class super1 { int x; super1(int x) { this.x=x; } abstract void display(); /* { System.out.println("Super x is = "+x); }*/ } class sub1 extends super1 { int y; sub1(int a, int b) { super(a); this.y=b; } void display()

{ System.out.println("Super value of x is = "+x); System.out.println("Sub value of y is = "+y); } } class abstracttest { public static void main(String args[]) { // super1 su=new super1(10); sub1 s=new sub1(11,11); s.display(); } }//END

Vous aimerez peut-être aussi