NAME : DEEPMOINA BORUAH
REGISTRATION NO : C2300495
ROLL NO :23992023
COURSE : BCA
SEMESTER : 2ND SEM
PAPER CODE : Pr-2.5
SUBJECT : COMPUTER APPLICATION
PAPER TITEL : OOPS USING JAVA
DATE : 22-06-2024
D
Q1. Create a Java Program to demonstrate inheritance with a base class shape and derived
classes Rectangle and circle.
Ans:
Program:
class shape {
void two_D() {
System.out.println("It is a 2d shape.");
class Circle extends shape {
void Area(float r) {
System.out.println("Area of the Circle: "+(3.14*r*r));
class Rectangle extends shape {
void Area(int l, int b) {
System.out.println("Area of the Rectangle: "+(l*b));
public class TestMultilevelInheritance {
public static void main(String[] args) {
Circle c = new Circle();
Rectangle r = new Rectangle();
c.two_D(); // Inherited method
c.Area(5); // Inherited method
r.two_D();
r.Area(5, 6);
Output:
Q2. Write a program demonstrate method overloading and overriding.
Ans:
Program:
// Java program to demonstrate method overloading and method overriding.
class addition {
static int add(int a, int b) {
return a+b;
static int add(int a,int b, int c, int d) {
return a+b+c+d;
class Animal {
void sound() {
System.out.println("Animals make sound");
class Cat extends Animal {
void sound() {
System.out.println("Cats Meows");
class Dog extends Animal {
void sound() {
System.out.println("Dogs Bark");
class method {
public static void main(String[] args) {
System.out.println(addition.add(40,80));
System.out.println(addition.add(40,50,70,160));
Dog d = new Dog();
d.sound();
Cat c = new Cat();
c.sound();
Output: