Академический Документы
Профессиональный Документы
Культура Документы
OUTPUT:
JAVA LAB
OUTPUT:
The total is:180
class inhertest { public static void main(String args[]) { bedroom room1=new bedroom(14,12,10); int area1=room1.area; int volume1=room1.volume(); System.out.println(Area=+area1); System.out.println(Volume=+volume1); } } // superclass method // baseclass method
OUTPUT:
Area1=168 Volume1=1680
class calc { public int multiply(int a,int b) { System.out.println("Values of a and b are:"+a+" & "+b); System.out.println("multiplying two integer values:"); return a*b; } public double multiply(double a,double b) //performing same operation usin diff inputs(polymorphism) { System.out.println("Values of a and b are:"+a+" & "+b); System.out.println("multiplying two double values:"); return a*b; } } class poly { public static void main(String S[]) { calc c=new calc();//creating object System.out.println(c.multiply(5,10)); System.out.println(c.multiply(1000.6,1000.5)); } }
OUTPUT:
Values of a and b are:5 & 10 multiplying two integer values: 50 Values of a and b are:1000.6 & 1000.5 multiplying two double values: 1001100.3
OUTPUT:
Understanding the usage of static methods Square value is:2500 square value is:2401 End of the program
class emp { static int id=1; int a,b; static void id() { System.out.println("Object numer:"+id); id++; } emp() { System.out.println("ID of objects:"); } int add(int x,int y) { x=a; y=b; return x+y; } } class s { public static void main(String S[]) { int v,w; emp obj1=new emp(); obj1.a=10; //object creation //constructor // static method // static variable
obj1.b=200; emp.id(); v=obj1.add(100,200); System.out.println("The sum is:"+v); emp obj2=new emp(); obj2.a=40; obj2.b=40; emp.id(); w=obj2.add(30,40); System.out.println("The sum is:"+w); } }
OUTPUT:
ID of objects: Object numer:1 The sum is:210 ID of objects: Object numer:2 The sum is:80