What will be the result of compiling and executing the code listed below?


Code
  1.  

  2. public class Finder {

  3. public static void main(String[] args){

  4. System.out.println(X.Y.Z);

  5. }}

  6. class X{

  7. static class Y{ static String Z ="Apple"; }

  8. static W Y = new W();

  9. }

  10. class W{ String Z = "Orange";}
Copyright GeekInterview.com

a) Apple

b) Orange

c) Compile time Error

d) Runtime Exception is thrown

Questions by lalithakasiraj

Showing Answers 1 - 21 of 21 Answers

zhiv

  • Feb 7th, 2013
 

Compile Time Error

  Was this answer useful?  Yes

Answer is B. Orange

Static block always executed before invoking the main method. here, we are creating object of class W. So, it will print Orange

  Was this answer useful?  Yes

Abhinav Rohatgi

  • Apr 1st, 2013
 

Orange

  Was this answer useful?  Yes

yuvraj

  • Jun 28th, 2016
 

b) Orange

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions