Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

LAB-7

A lab Submitted
in Partial Fulfilment of the Requirements
for the Degree of
Bachelor of Technology/BTech (CSE)

As part of “JAVA PROGRAMMING ” course


By
Harsh Singh
To
Dr. Arpit Bhardwaj

SCHOOL OF ENGINEERING AND TECHNOLOGY


BML MUNJAL UNIVERSITY GURGAON
#CODE

import java.util.*;

class Animal{

void sleep(){

System.out.println("Zzzzzz");

void Noise(){

System.out.println("Grrrr");

void roam(){

System.out.println("Roaming near water");

class Wolf extends Animal{


void Noise(){

System.out.println("Howling:Ouooooo!");

class Lion extends Animal{

void Noise(){

System.out.println("Roar:Rrrrrr");

class Cat extends Animal{

void Noise(){

System.out.println("Meow Meow");

public class Main

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int a=sc.nextInt();

Animal s1 = new Lion();

Animal s2 = new Cat();

Animal s3 = new Wolf();

switch(a){

case 1: {

s3.Noise();

s3.sleep();

s3.roam();

break;
}

case 2: {

s1.Noise();

s1.sleep();

s1.roam();

break;

case 3: {

s2.Noise();

s2.sleep();

s2.roam();

break;

default:

#OUTPUT
#CODE

import java.util.Scanner;

class Shape{

void area(int a){

System.out.print("Area of square: ");

System.out.println(a*a);

void area(int a, int b){

System.out.print("Area of rectangle: ");

System.out.println(a*b);

class Compute extends Shape {

void area(int a){

System.out.print("Area of circle: ");

System.out.println((3.14)*a*a);
}

class Main

public static void main(String[] args) {

Shape x = new Shape();

Shape y = new Compute();

Scanner sc= new Scanner(System.in);

System.out.println("Enter value of a: ");

int a = sc.nextInt();

System.out.println("Enter value of b: ");

int b = sc.nextInt();

x.area(a);

x.area(a,b);

y.area(a);

#OUTPUT

You might also like