DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment - 3
Student Name: Saket kumar UID: 24BCS12223
Branch: B.E.-CSE Section/Group: 617-B
Date of Performance: 11-03-2026 Semester: 4th
Subject Name: Object Oriented Programming Using Java Subject Code: 24CSH-207
Aim1 : Packageforshape
Createapackageshapewith the following classes:
[Link] 2. rectangle
Eachclassesshouldhave method to calculate area now acces the method in
main class.
Aim 2 : custom exception
Createacustomexception class called invalid age Exception write a program that
throwsthisexceptionifthe age entered by the user less than 18.
Code 1:
Aim 1:
packageShapes;
public class circle {
publicdoublecarea(int r){
return3.14*r*r;
}
}
publicclassrectangle{
publicintrarea(int l,int b){
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return l*b;
}
}
import [Link];
import [Link];
publicclassAccesing_package {
staticvoidmain(){
rectangleR=new rectangle();
circleC=newcircle();
[Link]([Link](5,6));
[Link]([Link](4));
}
}
Code 2:
Aim 2:
import [Link];
publicclassInvalidAgeException {
static void main() {
Scannersc=newScanner([Link]);
try{
int age;
age=[Link]();
if(age<18) throw new Exception();
[Link]("you are eligible");
}
catch (Exception e) {
[Link]("age must be 18 or above");
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
Aim:1
Output:
Aim:2