Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java nested class example
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ratna rathor
Java nested class example
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


Give me any example of Nested Class.


Advertisement
View Answers

May 17, 2012 at 5:48 PM


Nested Class: Class defined within another class is called nested class. Nested class is divided into two parts-

1.Static

2.Non-static Static nested class is declared static. Non-static nested class is also called inner class.

Example:

public class NestedClass{
    private String outer = "Outer Class"; //NestedClass instance variable
    InnerClass innerClass = new InnerClass();
    void getOuterS(){
        System.out.println(outer); 
    }
    void getInnerS(){
        System.out.println(innerClass.inner);
    }
    class InnerClass{
        private String inner = "Inner Class"; //InnerClass instance variable, uninitialized
        void getInnerS(){
            System.out.println(inner);
        }
        void getOuterS(){
            System.out.println(NestedClass.this.outer);
        }
    }
    public static void main(String[] args){
        NestedClass nestedClass = new NestedClass();
        NestedClass.InnerClass nestedInner = nestedClass.new InnerClass();//can also be new NestedClass().new InnerClass ();
        nestedClass.getOuterS();
        nestedClass.getInnerS();
        nestedInner.getInnerS();
        nestedInner.getOuterS();
    }
}


Related Tutorials/Questions & Answers:
Java nested class example
Java nested class example  Give me any example of Nested Class.   Nested Class: Class defined within another class is called nested class. Nested class is divided into two parts- 1.Static 2.Non-static Static
The nested class - Java Beginners
The nested class  Hi, What is nested class in Java? What is the benefits of nested class? Write examples of nested class. Thanks   .../java/n/java-nested-class.shtml Thanks
Advertisements
Java inner class and static nested class
Java inner class and static nested class  Java inner class and static nested class
Nested class
Nested class  What is nested class?  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
Java Nested Class
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
Nested class in java
class. To derive a class in java the keyword extends is used. For more details click on the following link. Nested class and inheritance in java... through which we can derived classes from other classes. The derived class
Example of HashMap class in java
Example of HashMap class in java. The HashMap is a class in java collection framwork. It stores values in the form of key/value pair. It is not synchronized
Example of HashSet class in java
Example of HashSet class in java. In this part of tutorial, we... unique. You can not store duplicate value. Java hashset example. How.... Example of Hashset iterator method in java. Example of Hashset size() method
Nested Loop - Java Beginners
Nested Loop  Hi, Can anyone tell me example of Nested loop in Java? Thanks   Hi friend,public class NestedExample{ public static void main(String[] args){ /** Print Pattern I */ System.out.println("
Inner class in java
Inner class in java In this example we will describe inner classes in java. Inner class declared inside a class. The inner class also call Nested classes... class parts of Nested Class. Inner classes are related by different names
Static Nested Classes
; A nested class that is declared static is called a static nested class... independently of any particular outer class object. A static nested class use... an object reference. A static nested class interacts with the instance
Nested classes
class looks just like any other class, except that it is nested inside another class. ( It can even contain further levels of nested classes, but you... inner class can be either static or non-static. A static nested class
Inner Nested Classes
of inner nested class with the help of an example. There is an inner class... nested classes, a non-static nested class is actually associated to an object rather than to the class in which it is nested. Any member
Struts nested tag Example
Struts nested tag Example   ... Create a second java class Authors in the same package roseindia.web.common.... a java class AuthorsBooksForm in the package roseindia.web.struts.form, which
Java Wrapper Class Example
Java Wrapper Class Example In this section we will read about how to use... to objects of that class. In Java there are eight primitive data types and each data... about how to use the wrapper classes in Java. In this example we will create
Use of Local Inner class
;  The Java language enables you to define a class inside another class. Such a class is defined as Nested Class or Local Inner class. The Nested Class are classified into - 1)Static Nested Inner class are declared static called
MySQL Nested Example
MySQL Nested Example      ... of nested select query specified in Where Clause. Understand with Example The Tutorial illustrate an example from 'MySQL Nested Select'. To understand
MySQL Nested Select Example
MySQL Nested Select Example       MySQL Nested Select is select query, that is nested inside... with Example The Tutorial illustrate an example from 'MySQL Nested Select'. To understand
Example for a method in java which returns a class
Example for a method in java which returns a class  Hi, I want to create a 1 class,and declare some methods there.I need to method must returns a classname.when i call that particular method(which returns a class),how can i
Nested If Statement
. Here we are providing you an example using Nested-If statement. In the example, we... Nested If Statement       In this section you will study about the Nested-if Statement in jsp
Class Cast Exception Example in java
Class Cast Exception Example in java We are going to describe class cast exception in java. The class cast exception is a converting one data type into another data type. A Class cast exception is a thrown by java. In this example
Create a Popup Menus with Nested Menus in Java
Create a Popup Menus with Nested Menus in Java  ... a nested popup menu in Java Swing. When you click the right mouse button... like: folder, text document and shortcut. Following figure shows the nested popup
Java Abstract Class Example
Java Abstract Class Example In this section we will read about the Abstract class. Abstract class in Java is a class which is created for abstracting... this example into two parts, in first part we will create an abstract class and we
Example to show class exception in java
Example to show class exception in java       In this Tutorial we are describing the example to show the use of class exception in java .Exceptions are the condition 
Nested classes: Examples and tutorials
Nested classes Here is another advantage of the Java... within another class, such class is called a nested class. Inner classes can...; Static Nested Classes A nested class that is declared static is called
Java 8 consumer class(interface) example
How to use the Java 8 consumer class(interface)? In this example program I...); } } //Consumer implementation example class ConsumerObject implements...("Value is:"+t); } } Read more tutorials and example of Java 8
Java Bigdecimal class example
Java Bigdecimal class example       Java bigdecimal class comes under java.math library. Class... increased the usage of this class in building Business applications.  Java
Nested try
, visit the following link: Nested Try Example...Nested try  Each time when i execute this code in eclipse i get different answers pl help me with this code class Demo { static void nestedTry
Real Time Example Interface and Abstract Class - Java Beginners
Real Time Example Interface and Abstract Class  Hi Friends, can u give me Real Time example for interface and abstract class.(With Banking Example
java inner class - Java Beginners
java inner class  What is the difference between the nested class and inner class? Explain with suitable example.  Hi Friend, Differences: 1)Nested class is declared inside another class with the static keyword
Member Classes, Inner Nested Classes in java
;  Member classes are defined within the body of a class. We can use member classes anywhere within the body of the containing class. We declare member classes when we want to use variables and methods of the containing class without
 

 

 

DMCA.com