Nitesh Nandwana

Ranch Hand
+ Follow
since Jun 07, 2011
Nitesh likes ...
Firefox Browser Notepad Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
19
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nitesh Nandwana

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.




from k&B
Rules for Constructors

Constructors can use any access modifier, including private. (A private constructor means only code within the class itself can instantiate an object of that type, so if the private constructor class wants to allow an instance of the class to be used, the class must provide a static method or variable that allows access to an instance created from within the class.)


in above example you're using static method that allows to an instance creation that is correct but how using static variable as written above ??

Dennis Deems wrote:What Eli said.



Yes I got that but i want to use static instance variable to create that class object not static reference variable, how ???

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);
}

}



if there is a method in ClassA then how can i access it in ClassB using this static instance variable means i want to use this static instance variable to create object of ClasssA .

Eduardo Mineo wrote:

When I was getting myself prepared to OCJP, I realized that confusion is the aim of the test.
--eduardo



You're wrong if you 're confused , means you've lost everything

Suhail 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

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 6

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,



Yes sure that'll be absolutely correct, i thought you're talking about above examples.

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,



Prithvi i don't think there is need of enclosing class name, enum is inside or outside, it'll never matter as you can see above example.

Rituka Jaiswal wrote:Can anyone explain in more detail, still unable to understand fully..
Why false was printed on the console?



First you've to use code tag else noone help you

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.



why are you using class name ? that is not right way.It is not matter that enum is declared and defined outside or inside..this'll be correct always


here you're just assigning one value to size variable from enum named CoffeeSize not from class.

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...



Both are good defiantly you should try

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.



That is book for SCJP by Mr. Khalid and Mr. Rolf.