This is a Java program which shows the use of class in the program
Program:
- class Rectangle
- {
- int height;
- int width;
- void area()
- {
- int result=height*width;
- System.out.println(“The area is ”+result);
- }
- }
- class classDemo
- {
- public static void main(String args[])
- {
- Rectangle obj=new Rectangle();
- obj.height=10;//setting the attribute values
- obj.width=20;//from outside of class
- obj.area();//using object method of class is called
- }
- }
No comments:
Post a Comment