On 6/22/2018 3:54 AM,
[email protected] 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);
}
}
--
[email protected]d
Nine hundred forty-two days to go.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)