KEMBAR78
Dabopriya Goldar - (d222307714) Java Assignment | PDF | Area | Constructor (Object Oriented Programming)
0% found this document useful (0 votes)
5 views7 pages

Dabopriya Goldar - (d222307714) Java Assignment

The document contains multiple programming problems demonstrating concepts of inheritance, parameterized constructors, and method overriding in Java. It includes classes like Circle, Cylinder, Parent, Child, Rectangle, and Cuboid, showcasing their functionalities such as calculating area, volume, and method overriding. Each problem is followed by a main method that tests the implemented classes and methods.

Uploaded by

bongnewtown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Dabopriya Goldar - (d222307714) Java Assignment

The document contains multiple programming problems demonstrating concepts of inheritance, parameterized constructors, and method overriding in Java. It includes classes like Circle, Cylinder, Parent, Child, Rectangle, and Cuboid, showcasing their functionalities such as calculating area, volume, and method overriding. Each problem is followed by a main method that tests the implemented classes and methods.

Uploaded by

bongnewtown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Labwork 2

Problem 1: Inheritance

class Circle
{
public double radius;

public double area()


{
return Math.PI * radius *radius;
}

public double perimeter()


{
return 2*Math.PI*radius;
}
public double circumference()
{
return perimeter();
}
}

class Cylinder extends Circle


{
public double height;

public double volume()


{
return area()*height;

1
}

public class Circle1


{

public static void main(String[] args)


{
Cylinder c=new Cylinder();

c.radius=7;
c.height=10;

System.out.println("Volume "+c.volume());
System.out.println("Area "+c.area());

Problem 2: Parameterized Constructors

class Parent
{
Parent()
{
System.out.println("Non-Param of parent");
}
Parent(int x)
{

2
System.out.println("Param of parent "+x);
}
}

class Child extends Parent


{
Child()
{
System.out.println("Non-Param of child");
}
Child(int y)
{
System.out.println("Param of child"+y);
}
Child(int x,int y)
{
super(x);
System.out.println("2 param of child "+y);
}
}
public class Main
{public static void main (String args[])
{Child c=new Child(10,20);

}
}
Problem 3 - parameterized constructors

class Rectangle
{
int length;
int breadth;

3
Rectangle()
{
length=breadth=1;
}
Rectangle(int l,int b)
{
length=l;
breadth=b;
}

class Cuboid extends Rectangle


{
int height;

Cuboid()
{
height=1;
}

Cuboid(int h)
{
height=h;
}
Cuboid(int l,int b,int h)
{
super(l,b);
height=h;
}

int volume()

4
{
return length*breadth*height;
}
}

public class Main


{
public static void main(String[] args)
{

Cuboid c=new Cuboid(5,3,10);


System.out.println(c.volume());
}
}
// Problem 4: Method overriding

// Problem 4: Method overriding

class Super
{
public void display()
{
System.out.println("Super Display");
}
}

class Sub extends Super


{
public void display()
{
System.out.println("Sub Display");
}

5
}

public class Main


{
public static void main(String[] args)
{
// Super s=new Super();

Sub s=new Sub();


s.display();
}
}

class Super
{
public void meth1()
{
System.out.println("Super Meth1");
}

public void meth2()


{
System.out.println("Super Meth2");
}
}

class Sub extends Super


{

6
public void meth2()
{
System.out.println("Sub Meth2");
}

public void meth3()


{
System.out.println("Sub Meth3");
}
}

public class Main


{
public static void main(String[] args)
{
Super sup=new Sub();
sup.meth1();
sup.meth2();
}
}

You might also like