Professional Documents
Culture Documents
OOPs Imp Questions
OOPs Imp Questions
OOPs Imp Questions
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);
@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;
@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.");
}
}
Output: