Discussion:
compiler error <identifier> expected.
(too old to reply)
t***@gmail.com
2015-09-02 09:32:39 UTC
Permalink
Hi Team,

I'm new to Java when I write a program for class and objects, when I try to compile the program getting an error message saying "error: <identifier> expected"


Here is the program.

class Card
{
int icount;
Static int tcount;
void swipe()
{
icount++;
tcount++;
}
}

class Demo9
{
public static void main(Static ar[])
{

Card v= new Card();
Card b= new Card();
v.swipe();
b.swipe();
b.swipe();
v.swipe();
v.swipe();
int total= Card.tcount;
int Vikas= v.icount;
int banu= b.icount;

System.out.println("Total students" + total);
System.out.println("Vikas students" + vikas);
System.out.println("Banu students" + banu);
}
}





Truly appreciate your response.
Jukka Lahtinen
2015-09-02 11:18:46 UTC
Permalink
Post by t***@gmail.com
I'm new to Java when I write a program for class and objects, when I try to compile the program getting an error message saying "error: <identifier> expected"
That's because you try to refer to "vikas" which you haven't defined
anywhere.
Post by t***@gmail.com
int Vikas= v.icount;
See, there you define "Vikas" starting with a capital V.
Post by t***@gmail.com
System.out.println("Vikas students" + vikas);
And this is where the compiler complains because it doesn't know what
"vikas" is.
--
Jukka Lahtinen
Eric Sosman
2015-09-02 12:29:29 UTC
Permalink
Post by t***@gmail.com
Hi Team,
I'm new to Java when I write a program for class and objects, when I try to compile the program getting an error message saying "error: <identifier> expected"
Here is the program.
class Card
{
int icount;
Static int tcount;
"Static"? Did you mean "static"? They are not the same.
Post by t***@gmail.com
void swipe()
{
icount++;
tcount++;
}
}
class Demo9
{
public static void main(Static ar[])
"Static"? Did you mean "String"?
Post by t***@gmail.com
{
Card v= new Card();
Card b= new Card();
v.swipe();
b.swipe();
b.swipe();
v.swipe();
v.swipe();
int total= Card.tcount;
int Vikas= v.icount;
int banu= b.icount;
System.out.println("Total students" + total);
System.out.println("Vikas students" + vikas);
"vikas"? Did you mean "Vikas"? (Or perhaps the earlier
appearance should have been "vikas" instead of "Vikas"?)
Post by t***@gmail.com
System.out.println("Banu students" + banu);
}
}
Truly appreciate your response.
Letter case matters in Java source code: "class" and "Class"
are different, "hashcode" and "hashCode" are different, ...
--
***@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Loading...