Pages

Saturday, April 21, 2018

Constructor in JAVA

#Constructor Example 

import java.util.*;
class Constructor
{
  int l,b;
  Constructor()   // Default Constructor;
  {
   
    Scanner s=new Scanner(System.in);
    System.out.println("Enter the l and b:");
    l=s.nextInt();
    b=s.nextInt();
    //l=5;
    //b=6;
  }
  void area()
  {
    int areas;
    areas=l*b;
    System.out.println("Area is :"+areas);
  }
  public static void main(String[] b)
  {
    Constructor c=new Constructor();
    c.area();
  }
}

No comments:

Post a Comment