Free SCJP ebook!

Free SCJP Mock exams!( Registration required)
The free SCJP ebook
Witscale Test Center

Previous Page Next Page Contents Index

Valid XHTML 1.0!

Nested Classes

Inner Classes
An inner class is a type of nested class that is not explicitly or implicitly declared static.

Inner class types
  • Local inner class.
    • A local class is a nested class that is not a member of any class and that has a name.
    • Every local class declaration statement is contained by a block.
    • The scope of a local class declared in a block is within the rest of the block.
    • Local class defined in a method has access to final method variables and also to the outer class's member variables.
    example [More in ebook]
  • Anonymous inner class.
    • Anonymous inner class does not have name.
    • It can extend a class or implement an interface but cannot do both at the same time. (For example, an anonymous inner class cannot say extends and implements at the same time.)
    • The definition, construction and first use of such class is at same place.
    • Programmer cannot define specific constructor for anonymous class but he/she can pass arguments (to call implicit constructor of its super class.)
    • An anonymous class is never abstract. An anonymous class is always an inner class; it is never static. An anonymous class is always implicitly final.
    • Anonymous class defined in a method has access to final method variables and also to the outer class's member variables.
    [More in ebook]
  • Non-static member class.
    • A member class is a inner class whose declaration is directly enclosed in another class or interface declaration.
    • Member inner class can be public, private, protected or default/friendly.
    • Non-static member inner class has access to member variables of the outer class.
    • Non-static member inner class can be instantiated on the instance of the outer class.
    example
  • [More in ebook]
Static nested classes.
  • Nested class can also be static. It has access to only static member variables of the outer class.
  • Static nested class may be instantiated/accessed without the instance of the outer class. It is accessed just like any other static member variable of a class.
    For example, instance method accessTest() of public static nested class "Inner" can be invoked as...

    new com.witscale.scjp.examples.Outer.Inner().accessTest();
    
[More in ebook]



Related SCJP Objective

Section 4 : Language Fundamentals
  1. Identify correctly constructed package declarations, import statements, class declarations (of all forms including inner classes) interface declarations, method declarations (including the main method that is used to start execution of a class), variable declarations, and identifiers.
  2. Identify classes that correctly implement an interface where that interface is either java.lang.Runnable or a fully specified interface in the question.
  3. State the correspondence between index values in the argument array passed to a main method and command line arguments.
  4. Identify all Java programming language keywords. Note: There will not be any questions regarding esoteric distinctions between keywords and manifest constants.
  5. State the effect of using a variable or array element of any kind when no explicit assignment has been made to it.
  6. State the range of all primitive formats, data types and declare literal values for String and all primitive types using all permitted formats bases and representations.

[More in ebook]
Previous Page Next Page Contents Index Top of this page

Valid CSS!