Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

ID:10 SCJP Question of the day !!!

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reference to Rules !!!

-------File 1------------------------------


-------------------------------------------

------File 2 -------------------------------


-------------------------------------------


------File 3 -------------------------------


-------------------------------------------


What is the Output ??? or Compiler error ?? or runtime error ???
If you are new please do refer the rules by navigating through the above reference link
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will compile and run properly with out any error.

reason:
1. *public static void main(String... args)* compiler interpreted as public static void main(String[] args) ; It is Ok.

2. secondly, name is protected in parent package so, still in can be visible to Parent class which is in the same package.

hth
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with Venkat that output is Rally's without any compilation error.
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Just to confuse you all "


Have you heard that " protected members becomes private when inherited by a class in different package except for subclasses "

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe there will be a compiler error, because while the member name is visible for the Sam class (because its marked as protected and Sam inherits it), it will be seen as private to other classes in the same package as Sam (because it inherits it from a class in another package). Therefore giving a compiler error when Parent class tries to access it.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rene,
your logic would be correct if name were declared with default access. protected access means that it can be seen within the same package or in any subclass regardless of package, therefore the code does compile.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the classes compiles with out any error.

protected variable name is being inherited by Sahil from another package and from that Sam inherited it ,on which we are getting the variable, it should compile fine.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic