In Java programming language, when a class is defined within another class then such a class is called a nested class. Nested classes are a feature of Java that is included in jdk1.1.
The reasons of why we use nested classes are:
These classes are divided into two categories: static and non-static.
Nested classes that are declared static
are simply called static nested classes. A
static class has no access to instance-specific data.
Non-static nested classes are called inner
classes.
It has access to all of its enclosing class's instance data, including
private fields and methods.
Nested classes are associated with the enclosing class
itself, whereas inner classes are associated with an object of the enclosing
class.
The given class structure
shows the way of using the nested class.
|
class OuterClass { ... static class StaticNestedClass { ... } class InnerClass { ... } } |
Java
main Method
Every Java program must have one main method. The main
method is the first method, which the Java Virtual Machine executes. In other
words, when you execute a class with the Java interpreter, the runtime system
starts by calling the class's main() method. The main()
method then calls all the other methods required to run your application. The
main method is the entry point in the Java program and java program can't run
without main method.
The signature of main() method looks like this:
public static void main(String args[])
The method signature for the main()
method contains three modifiers:
public
indicates that the main()
method can be called by any object.static
indicates that the main()
method is a class method.void
indicates that the main()
method has no return value.Read more at
http:/www.roseindia.net/java/master-java/underStandingHello.shtml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java Nested Class
Post your Comment