hello i immediately need help!!!
i am trying to learn overloading and i am in 10 standard so please help me
i am getting identifier expected error
hello i immediately need help!!!
i am trying to learn overloading and i am in 10 standard so please help me
i am getting identifier expected error
import jav.io.*;
public class Overload
{
double r,side,l,b,AreaSquare,AreaCircle,AreaRectangle;
public void area(side)//this the line where error occurs
{
side1=side;
AreaSquare=side1*side1;
System.out.println("AREA OF SQUARE="+Areasquare);
}
public void area(l,b)
{
l1=l;
b1=b;
AreaRectangle=l1*b1;
System.out.println("AREA OF RECTENGLE="+AreaRectangle);
}
public void area(r)
{
r1=r;
PI=3.14;
AreaCircle=PI*r1*r1;
System.out.println("AREA OF CIRCLE="+AreaCircle);
}
public static void main()throws IOException
{
BufferedReader in=new BufferedReader (new InputStreamReader(System.in));
Overload obj=new Overload();
System.out.println("ENTER THE SIDE OF SQUARE=");
side1=Double.parseDouble(in.readLine());
System.out.println("ENTER THE LENGTH OF RECTANGLE=");
l1=Double.parseDouble(in.readLine());
System.out.println("ENTER THE BREADTH OF RECTANGLE=");
b1=Double.parseDouble(in.readLine());
System.out.println("ENTER THE RADIUS OF CIRCLE=");
r1=Double.parseDouble(in.readLine());
obj.area(side);
obj.area(l,b);
obj.area(r);
}
}
On 6/22/2018 3:54 AM, fernandofernando998877@gmail.com wrote:
hello i immediately need help!!!
i am trying to learn overloading and i am in 10 standard so please help me i am getting identifier expected error
import jav.io.*;
"jav"?
public class Overload
{
double r,side,l,b,AreaSquare,AreaCircle,AreaRectangle;
public void area(side)//this the line where error occurs
You must tell Java what type `side' is: a `double', an `int',
or whatever. Thus, for example,
public void area(double side) // if `side' is a `double'
{
side1=side;
Similarly, you must specify the type of `side1'. Java cannot
just guess whether it should be a `double' or `float' or `long',
you must write what you intend. (You've made the same omission
several more times; I won't point them all out but will trust you
to fix them yourself.)
AreaSquare=side1*side1;
System.out.println("AREA OF SQUARE="+Areasquare);
}
public void area(l,b)
{
l1=l;
b1=b;
AreaRectangle=l1*b1;
System.out.println("AREA OF RECTENGLE="+AreaRectangle);
}
public void area(r)
I anticipate trouble with this overload, because if you decide
to make `r' a `double' and you have also made `side' a `double'
above, then Java will have no way to distinguish the two methods:
They will have identical parameter lists. (The names of parameters
don't disambiguate, only their number and types matter.)
{
r1=r;
PI=3.14;
FYI, the predefined constant `Math.PI' is considerably more
accurate.
AreaCircle=PI*r1*r1;
System.out.println("AREA OF CIRCLE="+AreaCircle);
}
public static void main()throws IOException
{
BufferedReader in=new BufferedReader (new InputStreamReader(System.in));
Overload obj=new Overload();
System.out.println("ENTER THE SIDE OF SQUARE=");
side1=Double.parseDouble(in.readLine());
System.out.println("ENTER THE LENGTH OF RECTANGLE=");
l1=Double.parseDouble(in.readLine());
System.out.println("ENTER THE BREADTH OF RECTANGLE=");
b1=Double.parseDouble(in.readLine());
System.out.println("ENTER THE RADIUS OF CIRCLE=");
r1=Double.parseDouble(in.readLine());
obj.area(side);
obj.area(l,b);
obj.area(r);
}
}
--
esosman@comcast-dot-net.invalid
Nine hundred forty-two days to go.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 493 |
Nodes: | 16 (2 / 14) |
Uptime: | 33:09:18 |
Calls: | 9,740 |
Files: | 13,741 |
Messages: | 6,183,303 |