Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.help Subject: Re: Compile error: java: expected Date: Sat, 23 Jun 2018 08:05:57 -0400 Organization: A noiseless patient Spider Lines: 79 Message-ID: References: <29442c5a-69a2-451a-88f0-25a5e0b9937e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 23 Jun 2018 12:06:01 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="84794ddaa2154a26dfeeb1893cacc44e"; logging-data="28291"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zGA0fsYNDlaX3XWgZPahu" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:Cu9uHnsZmM05bP/67kS+iRLfUC4= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.help:4223 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.