0% found this document useful (0 votes)
7 views5 pages

Oops

The document contains a programming assignment for a BCA course, focusing on Object-Oriented Programming (OOP) using Java. It includes two questions: the first demonstrates inheritance with classes for shapes (Circle and Rectangle), and the second illustrates method overloading and overriding with an addition class and animal classes. Sample Java code and expected outputs are provided for both questions.

Uploaded by

deepmoinaboruah7
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)
7 views5 pages

Oops

The document contains a programming assignment for a BCA course, focusing on Object-Oriented Programming (OOP) using Java. It includes two questions: the first demonstrates inheritance with classes for shapes (Circle and Rectangle), and the second illustrates method overloading and overriding with an addition class and animal classes. Sample Java code and expected outputs are provided for both questions.

Uploaded by

deepmoinaboruah7
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/ 5

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:

You might also like