//https://csprograms4u.blogspot.com/
//Chapter 3
//Program 3
//Parameterized constructor in Javaimport java.util.Scanner;
class circle
{
private double r;
circle()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter
radius");
r=sc.nextDouble();
}
circle(double r1)
{
r=r1;
}
public double area()
{
return 3.14*r*r;
}
}
public class
Parameterized_Constructor
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter
r");
double n=sc.nextDouble();
circle c1=new circle(n);
System.out.println("Area="+c1.area());
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.