JAVA Constructor Example Program
Write a JAVA Program to implement Constructor .
![]() |
JAVA Programming |
Program / Code:
import
java.util.Scanner;
class
Rectangle{
int l,b,r;
Rectangle(int x,int y){
l=x;
b=y;
}
void rectArea(){
r=l*b;
System.out.println("Area of
Rectangle="+r);
}
}
class
ParameterConst{
public static void main(String args[]){
int a,b;
System.out.print("Enter length
and breadth :");
Scanner in=new Scanner(System.in);
a=in.nextInt();
b=in.nextInt();
Rectangle obj=new Rectangle(a,b);
obj.rectArea();
}
}
Output:
JAVA Constructor |
No comments:
Your comment will be visible after review.