Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
a question
Syamsul Hussin
Ranch Hand
Posts: 59
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi.pls help me with this question
[ 26 ] Given: 1. public class Initialize{ 2. int x = 200; 3. static { 4. int x = 100; 5. } 6. public static void main(String[] args){ 7. Initialize init = new Initialize(); 8. System.out.println(init.x); 9. } 10. } What will happen when we attempt to compile and run this code? (Choose one.) A. The program will produce a Compile Error because of line 3. B. The program will produce a Compile Error because of line 4. C. The program will print "100". D. The program will print "200".
thanks.
----------------------------------<br />SCJP 1.4
jaya S K
Greenhorn
Posts: 20
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
The ans is program will print 200.
The variable x declared inside static block is local to that block.
So init.x will refer to the member variable declared in the class outside the static block.
Hope this helps.
Regards
Jaya S K
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
static variable -- confusion?
Markus, exam 1, Q43
no static??
Wanted some help about arrays
A Question for the group
More...