File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class" Watch "Inner class" New topic
Author

Inner class

joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117



Why do I get compilation error in the above code.
Some say that the method Method() in class Test is hided by Method() in
Outer class.
Can sombody put some light into this
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
15.12.1 Compile-Time Step 1: Determine Class or Interface to Search

The first step in processing a method invocation at compile time is to figure out the name of the method to be invoked and which class or interface to check for definitions of methods of that name. There are several cases to consider, depending on the form that precedes the left parenthesis, as follows:

  • If the form is MethodName, then there are three subcases:
  • [list]If it is a simple name, that is, just an Identifier, then the name of the method is the Identifier. If the Identifier appears within the scope (�6.3) of a visible method declaration with that name, then there must be an enclosing type declaration of which that method is a member. Let T be the innermost such type declaration. The class or interface to search is T.
  • If it is a qualified name of the form TypeName . Identifier, then the name of the method is the Identifier and the class to search is the one named by the TypeName. If TypeName is the name of an interface rather than a class, then a compile-time error occurs, because this form can invoke only static methods and interfaces have no static methods.
  • In all other cases, the qualified name has the form FieldName . Identifier; then the name of the method is the Identifier and the class or interface to search is the declared type T of the field named by the FieldName, if T is a class or interface type, or the upper bound of T if T is a type variable.

  • [/LIST]
    Barry Gaunt
    Ranch Hand

    Joined: Aug 03, 2002
    Posts: 7729
    I have renamed class Outer to XYZ because I found the name Outer is misleading. Test is the outer (or containing) class of class Inner. You can call Method() in the outer class as follows. Run main in class Test to see it work.
    [ September 14, 2006: Message edited by: Barry Gaunt ]

    Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
    Getting someone to think and try something out is much more useful than just telling them the answer.
    joshua antony
    Ranch Hand

    Joined: Jun 05, 2006
    Posts: 117
    Thanks Wise and Barry.

    So can I conclude that if a method is present in an inner class it cannot have overloaded version in parent class unless the parent class has overridden version of the method.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Inner class