Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InnerClass Question/ Exam Lab

 
Minu Sam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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.

 
Sarah Rising
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic