0% found this document useful (0 votes)
37 views3 pages

OOPs Imp Questions

The document describes an assignment to: 1. Define an abstract Figure class with area() and volume() methods, and concrete TwoDFigure and ThreeDFigure classes that override these methods. 2. Implement an interface design with an abstract C class, interfaces A and A1, and concrete class D that extends C and implements A.

Uploaded by

aditya.cse121118
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)
37 views3 pages

OOPs Imp Questions

The document describes an assignment to: 1. Define an abstract Figure class with area() and volume() methods, and concrete TwoDFigure and ThreeDFigure classes that override these methods. 2. Implement an interface design with an abstract C class, interfaces A and A1, and concrete class D that extends C and implements A.

Uploaded by

aditya.cse121118
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/ 3

Assignment - 7

Name – Sourasish Mondal


University Roll No. – 11500221053
Stream – CSE-B Group – 2
Subject – Object Oriented Programming
Subject Code – PCC-CS593

Problem Statement:

1. Define an abstract class figure. Define the area and volume method in the
child classes. Use dynamic method dispatch.

Code:
public class assignment7{
public static void main(String[] args){
Figure rectangle = new TwoDFigure(5, 10);
Figure box = new ThreeDFigure(10, 30, 20);

System.out.println("The area of the rectangle is:


" + rectangle.area());
System.out.println("The area of the box is : " +
box.volume());
}
}

abstract class Figure{


abstract double area();
abstract double volume();
}

class TwoDFigure extends Figure{


double length;
double breadth;

TwoDFigure(double length, double breadth){


this.length = length;
this.breadth = breadth;
}

@Override
double area(){
return length * breadth;
}

@Override
double volume(){
return 0; //not applicable for two dimension
figure
}
}
class ThreeDFigure extends Figure{
double length;
double breadth;
double height;

ThreeDFigure(double length, double breadth, double


height){
this.length = length;
this.breadth = breadth;
this.height = height;
}
@Override
double area(){
return 2*(length*breadth + breadth*height +
length*height);
}

@Override
double volume(){
return length * breadth * height;
}
}

Output:
2. Implement the following design with suitable example classes.

Code:

interface A {
void doSomething();
}
interface A1 {
void doSomething1();
}
abstract class C {
abstract void performAction();
}
class D extends C implements A {
@Override
void performAction() {
System.out.println("Class D performing an action.");
}
@Override
public void doSomething() {
System.out.println("Class D is doing something.");
}
public void doSomething1() {
System.out.println("Class D is doing something again.");
}
}

public class assignment7ii {


public static void main(String[] args) {
D d = new D();
d.performAction();
d.doSomething();
d.doSomething1();
}
}

Output:

You might also like