0% found this document useful (0 votes)
42 views

Inner Class Instance Has Access To All Member of The Outer Class (Public, Private & Protected)

Inner classes are classes defined within other classes. An inner class has access to members of its outer class as if they are members of the inner class. Inner classes allow nesting of related classes and can access private members of outer classes. Javadoc is a tool for extracting documentation comments from Java source code and generating HTML files containing the documentation. Documentation comments are special comments formatted with HTML tags that provide documentation for classes, methods, and other code elements.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Inner Class Instance Has Access To All Member of The Outer Class (Public, Private & Protected)

Inner classes are classes defined within other classes. An inner class has access to members of its outer class as if they are members of the inner class. Inner classes allow nesting of related classes and can access private members of outer classes. Javadoc is a tool for extracting documentation comments from Java source code and generating HTML files containing the documentation. Documentation comments are special comments formatted with HTML tags that provide documentation for classes, methods, and other code elements.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Inner classes are class within Class.

Inner class
instance has special relationship with Outer class.
This special relationship gives inner class access to
member of outer class as if they are the part of outer
class.
Inner class instance has access to all
member of the outer class(Public, Private &
Protected)
Syntax for creating Inner Class
1 //outer class
2 class OuterClass {
3 //inner class
4 class InnerClass {
5}
6}

If you compile above code it will produce two class file.


Note: You cant directly execute the inner classs .class
file with java command.

1
2
3
4
5
6

//outer class
class OuterClass {
//inner class
class InnerClass {
}
}

1 outer.class
2 inner$outer.class

How to access Inner Class

WithinOuter Class
Outer class can create instance of the inner class in the same way
as normal class member.
class OuterClass {
private int i = 9;

// Creating instance of inner class and calling inner class


function
public void createInner() {
InnerClass i1 = new InnerClass();
i1.getValue();
}

// inner class declarataion


class InnerClass {
public void getValue() {
// accessing private variable from outer class
System.out.println("value of i -" + i);
}
}
}

From Outside Outer Class


Create outer class instance and then inner class
instance.
class MainClass {

public static void main(String[] args) {


// Creating outer class instance
OuterClass outerclass = new OuterClass();
// Creating inner class instance
OuterClass.InnerClass innerClass = new OuterClass.new
InnerClass();
// Classing inner class method
innerclass.getValue();
}
}
OuterClass.InnerClass innerclass = outerclass.new
InnerClass();

javadocis a command-line tool for extracting special comments


(calleddoc comments)
from java source files and generating an easy-to-use HTML file tree
containing them.
The comments can include standardHTMLmarkup and javadoc
@tags.
The Java language supports three types of comments:
Comment

Description

/* text */

The compiler ignores everything


from /* to */.

// text

The compiler ignores everything


from // to the end of the line.

/** documentation */

This is a documentation comment


and in general its calleddoc
comment. TheJDK javadoctool
usesdoc commentswhen preparing
automatically generated
documentation.

A doc comment may be all on one line:


/** All on one line -- but still a doc comment. */
or span several lines:
/**
Spans several lines
still a doc comment
*/

The second and later lines of a


multi-line doc comment
/**
* For that 'retro'
* FORTRAN look.
*/
may begin with whitespace and
an asterisk, which javadoc
discards.

Javadoc organization
The HTML output generated byjavadocis organized like java
source is:
at the top level, as a group of several packages (with an
overview summary),
within a group, as individual packages (each with a
package summary),
within a package, as classes and interfaces (each with a
class or interface doc comment), and
within a class or interface, as fields (each with a
field doc comment), and constructors and methods (each with a
constructor or method doc comment).

/**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
*
* @author Zara Ali
* @version 1.0
* @since 2014-03-31
*/ public class HelloWorld
{
public static void main(String[] args)
{
/* Prints Hello, World! on standard output.
System.out.println("Hello World!");
}
}

You can include required HTML tags inside the


description part, for heading and has been used
forcreatingparagraph break:

/**
* <h1>Hello, World!</h1>
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
* <p>
* Giving proper comments in your program makes it more
* user friendly and it is assumed as a high quality code.
*
*
* @author Zara Ali
* @version 1.0
* @since 2014-03-31
*/
public class HelloWorld
{
public static void main(String[] args) {
/* Prints Hello, World! on standard output.
System.out.println("Hello World!");
}
}

The javadoc Tags: Thejavadoctool recognizes the following tags:


Tag
@author
{@code}

{@docRoot}

@deprecated

@exception

{@inheritDoc}

{@link}

{@linkplain}

Description
Adds theauthorof a class.
Displays text in code font
without interpreting the text
as HTML markup or nested
javadoc tags.
Represents the relative path
to the generated document's
root directory from any
generated page
Adds a comment indicating
that this API should no longer
be used.
Adds aThrowssubheading to
the generated documentation,
with the class-name and
description text.
Inherits a comment from
thenearestinheritable class
or implementable interface
Insertsan in-line link with
visible text label that points to
the documentation for the
specified package, class or
member name of a referenced
class. T
Identical to {@link}, except
the link's label isdisplayedin

Syntax
@author name-text
{@code text}

{@docRoot}

@deprecated deprecated-text

@exception class-name
description

Inherits a comment from the


immediate surperclass.
{@link
package.class#member label}

{@linkplain
package.class#member label}

You might also like