More Related Content
More from vishal choudhary (20)
Lab 3
- 2. • public class Test {
• public static void main(String arr[]) {
• int a=5;
• boolean b=true;
• char c='A';
• double d=34.25;
• System.out.println(a);
• System.out.println(b);
• System.out.println(c);
• System.out.println(d);
• }
• }
- 3. • public class test1 {
• public static void main(String[] args) {
• float a=(float)12.34;
• System.out.println(a);
• }
• }
- 4. • class Rectangle1
• {
• int l,b;
• public void display()
• {
• System.out.println("length="+l);
• System.out.println("breadth="+b);
• }
• }
• public class Rectangle extends Rectangle1 {
• public int area()
• {
• return l*b;
• }
• public void setDimension(int x,int y)
• {
• l=x;
• b=y;
• }
• }
public class RectangleTest {
public static void main(String[]
args) {
Rectangle r=new Rectangle();
r.setDimension(10, 30);
r.display();
System.out.println("Area="+r.ar
ea());
}
}
- 5. • public class test3 {
• int a,b;
• public test3(int a,int b)
• {
• this.a=a;
• this.b=b;
• System.out.println(" in two argument constructor");
• }
• public test3(int a)
• {
• this(a,10);
• System.out.println("it is one parameter construtor");
• }
• public test3()
• {
• this(2,3);
• System.out.println(" in defult constructor");
• }
• public void display()
• {
• System.out.println("a="+a);
• System.out.println("b="+b);
• }
• public static void main(String[] args) {
• test3 x =new test3();
• x.display();
• test3 y= new test3(10);
• y.display();
• test3 z =new test3(20,30);
• z.display();
• }