Reputation: 447
How can we use same name for class and object , without any issues from the compiler ?
class A{
public static void main (){
A A = new A ();
}
}
Or
class A{
public static void main(){
String String="java";
System.out.println(String);
}
}
How does the java compiler handle this?
Upvotes: 3
Views: 3242
Reputation: 9697
In Java it is absolutely correct to specify the name of the class and the name of the variable to be exactly the same. The compiler understands the syntax so it knows what part of the program represents the identifier and what part represents the class name.
But you should never do it as it will become a readability nightmare. Absolutely misleading and violating Java Naming Conventions.
Upvotes: 3