Eli Wood wrote:Nitesh, I believe the situation you are asking for is often seen in the Singleton pattern.
In my example, SimpleSingleton has a private contructor, and an instance (the only instance of the class) is held in a static variable. An accessor method, getInstance(), allows other classes to retrieve this instance, although you could avoid using a method and just set the static variable (theInstance) to public so it could be retrieved directly if you really wanted (I wouldn't recommend that though).
output:
Hello from an instance method! Object is sample.SimpleSingleton@82ba41.
Hello from an instance method! Object is sample.SimpleSingleton@82ba41.
Dennis Deems wrote:What Eli said.
raghava dv wrote:class ClassA{
static int a=3;
private ClassA(){}
}
public class ClassB{
static int b = 0;
public static void main(String arg[]){
b = ClassA.a;
System.out.println(b);
}
}
Eduardo Mineo wrote:
When I was getting myself prepared to OCJP, I realized that confusion is the aim of the test.
--eduardo
My dear don't fear open your ,,,,,,,book there is no difference, to call one point six is tough for some guys so we call it just 6Suhail Asif wrote:What is the difference between ocp jp 1.6 and "Java Standard Edition 6 Programmer Certified Professional Exam" . The latter one leads to Oracle Certified Professional, Java SE 6 Programmer.
Thanks
Prithvi Sehgal wrote:Nitesh,
Just look at the code properly. When the enum is inside another class, you need to give the name of the enclosing class.
The case you are talking about is, when enum is outside class or inside same class. We are discussing the case when enum
is part of another class. As the context changes, the using class will never know where that enum is and will complain a compile
time error.
HTH,
Prithvi Sehgal wrote:Dear Jean,
But when an enum is part of a class, you have to use the enclosing class name, else it won't
compile. Just think logically, how will other class know where the enum is declared so you need to specify the class
name, when an enum is present inside the class.
HTH,
Rituka Jaiswal wrote:Can anyone explain in more detail, still unable to understand fully..
Why false was printed on the console?
Jean John wrote:Hi,
I found the below code in SCJP book for Java 6 Exam and I have a doubt regarding the comment that enclosing class name is required. I tried without using the enclosing class name and still it works. The jdk i have right now is 1.6
The book mentions that the syntax for accessing an enum's members depends on where the enum was declared. But even if the enum is declared inside or outside the class, I can access the enum using the same syntax. ie. without enclosing class name. Can someone please bring out some clarity regarding this statement.Thanks.
Prasanna Nalamothu wrote:Well thank you friends,Am reading k.Mughal & Rolf,doesn't that book is sufficient or do i have to go for Kathy & Bates also...
Krish Devara wrote:Congratulations !! Just wanted to know what is K&R? Can I download it? Also where do I get the ecertify mock papers? Please let me know. Thanks.