Page 636 - Computer science 868 Class 12
P. 636
71 public static void main(String args[])
72 {
73 hcf_exception ob= new hcf_exception();
74 ob.entry();
75 ob.display();
76 }
77 }
Output of the preceding program is as follows:
Enter 2 numbers:
4
6
The HCF is2
The LCM is12
Program 24 Calculate area of circle and rectangle using Interface
An interface shape is defined as with a method area() which returns the area of the
implementing shape.
Create a class circle and rectangle which implement the interface shape. These classes have
attributes which reflects their dimension (radius for a circle, height and width for a rectangle)
which are set by their construction.
Details of the member of the interface and both the class:
Interface name : shape
Data Members
double area() : returns the area of the implementing shape
Class Name : Circle
Data Members
radius : to store radius of the circle in decimal
Member Functions
Circle(int r) : parameterised constructor to initialise radius r
double area() : to calculate area of the circle[area of the circle is
3.14*radius*radius]
Class Name : Rectangle
Data Members
length : to store the length of the rectangle in decimal
breadth : to store the breadth of the rectangle in decimal
Member Function
Rectangle (int l, int b) : parameterised constructor to initialise length l and breadth
double area() : to calculate the area of rectangle[area of rectangle
length*breadth]
1 import java.util.*;
634634 Touchpad Computer Science-XII

