0% found this document useful (0 votes)
44 views14 pages

Aoop Lab

Advance oop

Uploaded by

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

Aoop Lab

Advance oop

Uploaded by

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

Assignments of lab

Submitted by: MEHWISH MALIK

Submitted to: MS HUMAIRA BATOOL

Subject: Advanced OOP

Submission Date: 23rd September,2024.


Question number 1

Main class

package shape;

/**

* @author student

*/

public class MainClass {

public static void main(String[] args)

Shape shape=new Shape();

Circle circle=new Circle();

Rectangle rectangle =new Rectangle();

System.out.println("polymorphism using inheritance");

shape.show();

circle.show();

rectangle.show();

System.out.println("inherited method");

shape.getInfo();

circle.getInfo();

rectangle.getInfo();
}

package shape;

/**

* @author student

*/

public class Circle extends Shape {

public void show()

System.out.println("Circle");

package shape;

/**

*
* @author student

*/

public class Rectangle extends Shape {

public void show()

System.out.println("Rectangle");

package shape;

/**

* @author student

*/

public class Shape {

public void show()

System.out.println("Shape");

public void getInfo()

{
System.out.println("This is Shape class");

Output:
Question number 2:

package shape;

/**

* @author student

*/

abstract class Shape {

public abstract void show();

public void getInfo()

System.out.println("This is Shape class");

}
}

package shape;

/**

* @author student

*/

public class Circle extends Shape {

public void show()

System.out.println("Circle");

package shape;

/**

* @author student

*/

public class Rectangle extends Shape {


public void show()

System.out.println("Rectangle");

public class MainClass {

public static void main(String[] args)

Circle circle=new Circle();

Rectangle rectangle =new Rectangle();

System.out.println("polymorphism using inheritance");

circle.show();

rectangle.show();

System.out.println("inherited method");

circle.getInfo();

rectangle.getInfo();

}
}

Output:

Question number 6

package shape;

/**

* @author intag

*/

abstract class Shape {

int x, y;
Shape(int x, int y) {

this.x = x;

this.y = y;

abstract void printArea();

class rectangle extends Shape{

rectangle(int length, int width) {

super(length, width);

void printArea() {

System.out.println("Rectangle Area: " + (x * y));

class Triangle extends Shape {

Triangle(int base, int height) {

super(base, height);

void printArea() {

System.out.println("Triangle Area: " + (0.5 * x * y));

}
class circle extends Shape {

circle(int radius, int dummy) {

super(radius, 0);

@Override

void printArea() {

System.out.println("Circle Area: " + (3.14 * x * x));

} package shape;

public class main {

public static void main(String[] args) {

rectangle rectangle = new rectangle(10, 5);

rectangle.printArea();

Triangle triangle = new Triangle(10, 5);

triangle.printArea();

circle circle = new circle(5, 0);

circle.printArea();

}
Question number 7

interface Drawable {

void draw();

// Interface Measurable

interface Measurable {
double getArea();

double getPerimeter();

// Class Circle implementing Drawable and Measurable

class Circle implements Drawable, Measurable {

private double radius;

Circle(double radius) {

this.radius = radius;

public void draw() {

System.out.println("Drawing a circle with radius " + radius);

public double getArea() {

return Math.PI * radius * radius;

public double getPerimeter() {

return 2 * Math.PI * radius;

}
// Class Rectangle implementing Drawable and Measurable

class Rectangle implements Drawable, Measurable {

private double length;

private double width;

Rectangle(double length, double width) {

this.length = length;

this.width = width;

public void draw() {

System.out.println("Drawing a rectangle with length " + length + " and width " + width);

public double getArea() {

return length * width;

public double getPerimeter() {

return 2 * (length + width);

You might also like