This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Clarification on the answer given Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Clarification on the answer given" Watch "Clarification on the answer given" New topic
Author

Clarification on the answer given

kc pradeep
Greenhorn

Joined: Mar 05, 2011
Posts: 27

What is the output for the below code ?



Options are
A.0 false 0
B.0 true 0
C.0 0 0
D.Compile error - static variable must be initialized before use.
Answer :
A is the correct answer.
Global and static variable need not be initialized before use. Default value of global and
static int variable is zero. Default value of boolean variable is false. Remember local
variable must be initialized before use.

My question is can printValue() access static variable p?


OCPJP 6
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 867

kc pradeep wrote:What is the output for the below code ?



Options are
A.0 false 0
B.0 true 0
C.0 0 0
D.Compile error - static variable must be initialized before use.
Answer :
A is the correct answer.
Global and static variable need not be initialized before use. Default value of global and
static int variable is zero. Default value of boolean variable is false. Remember local
variable must be initialized before use.

My question is can printValue() access static variable p?


why can't it ? what are your reasons that printValue() cannot access static variable p ?


OCPJP 6(100 %) OCEWCD 6(91 %)
kc pradeep
Greenhorn

Joined: Mar 05, 2011
Posts: 27

oops sorry, I got confused with the other rule : static functions can only access static members.
yeah, non static functions can access both, right.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 867

kc pradeep wrote:oops sorry, I got confused with the other rule : static functions can only access static members.
yeah, non static functions can access both, right.


you got that.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Clarification on the answer given
 
Similar Threads
Small OO doubt
Local Variables
boolean practice question
Arrays declared as static or instance variables are initialized to null ?
a question about default constructor