Hi Mohit,
i'm not sure, if this is a multiple answer question or not. I would suggest d) and e) as solutions...
Originally posted by mohit joshi:
Something from my kitchen:
public class Class
{ Class Class = new Class();
public Class Class ( Class Class){
return Class;
}
}
a) The above example will not compile saying that Class Class already exists in package java.lang
b) The above example will not compile because Package name and Class name cannot be same.
c) The above example will not compile because a Class can not have a variable with the same name as the Class name itself.
d) The example compiles if we add line "package Class;" before the Class declaration.
e) The example compiles as it is.
[This message has been edited by mohit joshi (edited October 05, 2000).]
Since
Class is not a keyword or a reserved
word, you can use it as identifier. Same with
String String = "String".
For the initialization of
the default constructor of the newly created Class-Object is used. For a "normal" Class, one of type
java.lang.Class, you can't call the constructor, cause he is not visible.
Even if you define the package as java.lang it is no problem, cause in the worst case you will overwrite the existing java.lang.Class. BUT after you've done that, there could appear some problems
Correct me, if i'm wrong
cheers
Oliver