I'm trying to shift from C++ to Java.
What I wonder is, in C++, after a class definition, a semicolon (;
) is required, but in Java it isn't.
That is, in C++:
class Person {
public:
string name;
int number;
}; // Note this semicolon
But in Java:
class Person {
public String name;
public int number;
} // Semicolon is not required
That's fine, I understand that.
However, my problem is:
Java also works when I add semicolon at end of class definition, like:
class Person {
public String name;
public int number;
}; // Now this semicolon is confusing me!
I've compiled and executed both the program snippets shown for Java, and they both work. Can anyone explain why this is so? What does the semicolon at the end of a class definition in Java stand for?
I'm sorry if this question is of low quality, but I really need clarification for this. I hope experts in Java will help me.
Well, I've already seen Semicolons in a class definition and other related questions.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…