You are on page 1of 2

JAVA VIVA

Name: Ranjit Raj UID:20BCS9943

Q1. Write a program to print the area of a rectangle by creating a class named 'Area'
taking the values of its length and breadth as parameters of its constructor and having a
method named 'returnArea' which returns the area of the rectangle. Length and breadth
of rectangle are entered through keyboard.

CODE:

package com.company;

public class Area{


int length,breadth;
Area(int l,int b ){
length=l;
breadth=b;
}
public int setDim(){
int result= length* breadth;
return result;

}
public void getarea(){
System.out.println("Area= " +setDim());
}
public static void main(String[] args){
Area x=new Area(7,5);
x.getarea();
}

OUTPUT:

You might also like