This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes only static methods can access static members Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "only static methods can access static members" Watch "only static methods can access static members" New topic
Author

only static methods can access static members

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
...is this true or false?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

What happened when you tested this?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
i didnt test it...its a question from mughals book...its says the above sentence is false.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

Go ahead and test it, we anxiously await your results.
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
i know that only static methods can access static members....non static methods cant access them..then why is the above sentence false.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

When you test it, you will find that the statement is indeed false.
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
how? gimme an example
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

No one is here to do your work for you. Write an example yourself and you will see that your assumption is incorrect.
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
ok....u mean non static methods can access static members...i will try it
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
oh..i got it....static members can be accessed by non static and static methods....but static methods cannot access non static members
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

Bingo
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
thanks
Atwal Usha
Ranch Hand

Joined: Sep 10, 2009
Posts: 137
The statement is false as static members can be accessed from within non static as well as static context.


Java Certification Exam Mock Tests: SCJA  SCJP 5  SCJP 6  SCJP 6 (Online Training)  SCJP 6 (Instructor Led Training)   SCWCD 5   SCBCD 5  SCEA 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: only static methods can access static members
 
Similar Threads
Single tone Vs Static
WA #1.....word association
static and non static methods
property file dynamic vs static
static and non static methods