Saturday, 11 March 2017

Shows the use of class in the program in java

This is a Java program which shows the use of class in the program

Program:

  1. class Rectangle
  2. {
  3.  int height;
  4.  int width;
  5.  void area()
  6.  {
  7.   int result=height*width;
  8.   System.out.println(“The area is ”+result); 
  9.  }
  10. }
  11. class classDemo
  12. {
  13.  public static void main(String args[])
  14.  {
  15.   Rectangle obj=new Rectangle();
  16.   obj.height=10;//setting the attribute values 
  17.   obj.width=20;//from outside of class
  18.   obj.area();//using object method of class is called
  19.  }
  20. }


No comments:

Post a Comment