• 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

InnerClass Question/ Exam Lab

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see code below



I had a question since in the static method there is no this reference.I should not be even able to have a reference type of Engine.
It doesnt give a compilation error.However if i try to instantiate as in



it gives compilation error which makes sense.But why would the first case compile.I was thinking that i always need to access the inner class from a static method as OuterClassName.InnerClassMName, isnt that true?

Question 2:

I am trying to download examlab scjp 6 test , however i keep getting error file not found.Would appreciate if someone could help me.
 
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
static method expect static members for a class[or member can access via instance of a class using *new* key word, constructors are implicitly static]. however it wont mind about declaring class reference, it minds only about instance member of a class with out static reference/ new keyword.

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) The reason it fails to compile after you try to create an object of type Engine is because each Engine object needs an associated AirJet object. So an AirJet object must be created first, then the AirJet object can be used to create an Engine object, like this:



2) The reason your first compile attempt does not fail is that the compiler has no reason yet for it to fail. It can't predict if you'll correctly create an Engine object later. For example, like this:

reply
    Bookmark Topic Watch Topic
  • New Topic