NEW - Lab Manual Template
NEW - Lab Manual Template
(SCOPE)
- Exercise (Objective)
- Prerequisites
- Objectives
- Underlying Concept / Theory (along with Figure if
applicable)
- Problem Statement
- Algorithm
- Coding
- Output
- Remarks
- Conclusion
- Challenges
Exp
Date
. Title Remark
Conducted
No.
1
2
3
4
5
6
7
8
9
10
Hands-on Lab Manual (Experiment 7)
<Classes and Objects>
Exercise (Objective) 7: To demonstrate the concept of Classes
and Objects in JAVA.
Prerequisites:
You should already be familiar with:
Objectives:
After completion of this lab student shall be able to:
Algorithm:
Declare classes for each nouns used in problem statement.
Define /Initialize variables and functions.
Declare class containing main ( ) method.
Create / Initialize objects.
Coding:
Program 7:
class square{
int sqarea(int side){
int area = side * side;
return(area);
}
int sqpari(int side){
int pari = 4 * side;
return(pari);
}
}
class rectangle{
int rectarea(int length,int breadth){
int area = length * breadth;
return(area);
}
int rectpari(int length,int breadth){
int pari = 2*(length + breadth);
return(pari);
}
}
public class ObjectClass{
public static void main(String args[]){
int sarea1,sarea2,pari1,pari2;
int rectarea1,rectarea2,rectpari1,rectpari2;
square sq = new square();
rectangle rect = new rectangle();
int a=20;
System.out.println("Side of first square = " + a);
sarea1 = sq.sqarea(a);
pari1 = sq.sqpari(a);
System.out.println("Area of first square = " + sarea1);
int x = 10, y = 20;
System.out.println("Length of first Rectangle = " + x);
System.out.println("Breadth of first Rectangle = " + y);
rectarea1 = rect.rectarea(x,y);
System.out.println("Area of first Rectangle = " +rectarea1);
}
}
Output:
Side of first square = 20
Area of first square = 400
Length of first Rectangle = 10
Breadth of first Rectangle = 20
Area of first Rectangle = 200
Conclusion:
The objectives mentioned above are achieved successfully.