Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #4224
| Newsgroups | comp.lang.java.help |
|---|---|
| Date | 2018-06-23 09:03 -0700 |
| References | <29442c5a-69a2-451a-88f0-25a5e0b9937e@googlegroups.com> <a6a0ed07-1c7b-4211-ba81-448e93f4b7c7@googlegroups.com> <pgld39$rk3$1@dont-email.me> |
| Message-ID | <1f641fb6-cadf-443b-91e4-052ac1de6466@googlegroups.com> (permalink) |
| Subject | Re: Compile error: java: <identifier> expected |
| From | fernandofernando998877@gmail.com |
On Saturday, June 23, 2018 at 1:06:04 PM UTC+1, Eric Sosman wrote:
> 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.
thanks very much!!!
my program is working!!!
i will always be grateful to you!!!
you helped me to improve!!!
thanks!!! thanks!!!
thanks!!!
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar
Re: Compile error: java: <identifier> expected fernandofernando998877@gmail.com - 2018-06-22 00:54 -0700
Re: Compile error: java: <identifier> expected Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2018-06-23 14:37 +0300
Re: Compile error: java: <identifier> expected Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-06-23 08:05 -0400
Re: Compile error: java: <identifier> expected fernandofernando998877@gmail.com - 2018-06-23 09:03 -0700
csiph-web