Java Nested Class
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:
- It is a way of logically
grouping classes that are only used in one place.
- It increases encapsulation.
- Nested classes can lead to more readable and maintainable code.
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 themain()
method can be called by any object.static
indicates that themain()
method is a class method.void
indicates that themain()
method has no return value.
Read more at
http:/www.roseindia.net/java/master-java/underStandingHello.shtml
0