Forums Register Login

what might be the error

+Pie Number of slices to send: Send
hi folks,

package pack1;

class clas2{
String s1;
String s2;
void met(String d1, String d2)
{
System.out.println("ADASD");

}
}
public class rajaone
{
public static void main(String[] args)
{
//String s1,s2;
clas2 ref1 = new clas2();
ref1.s2; //error showing here
}
}


i am getting this error for the above code the error is :
---
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "AssignmentOperator ArrayInitializer" to complete Expression

at pack1.rajaone.main(rajaone.java:18)
thanks
raja
+Pie Number of slices to send: Send
Hi,

the line

references the member variable s2 of your instance ref1. Expected is a valid expression or a statement (e.g. an assignment, a method invokation)

examples:


hth - cheers
+Pie Number of slices to send: Send
Hi Thirumala Raju,

please try to make use of CodeTags so that the java code will look nicely.
+Pie Number of slices to send: Send
 

Originally posted by thirumala raju:
...hi folks,





What are you trying to achieve in the line in bold? You just used a variable using its reference. But it should be involved in an operation which may be of an assignment, arithmetic etc., The example shown by Nicolas is one kind.

You can call a method like this and leave its return type unassigned to any variable. But it is NOT the case with variables.
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 760 times.
Similar Threads
it's long but i can't help it.
Strings
== with Strings is giving a different result
Doubt in String class
another Question.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:55:10.