Java InnerClass

Java InnerClass

How can we use Inner Class in java program?

View Answers

June 15, 2012 at 4:34 PM

public class InnerClassExample{
    class InnerClass{
        String name = "Naulej";     
        @Override
        public String toString() {
            System.out.println(name);
            return super.toString();
        }
    }

    public InnerClassExample(){
        InnerClass innerClass = new InnerClass();
        System.out.println(innerClass.toString());
    }
    public static void main(String[] args){     
        new InnerClassExample();        
    }
}

Output

Naulej
InnerClassExample$InnerClass@19821f

Description:- The above code demonstrates you an Inner Class. An inner class is a class defined inside another class. Here, we have created a class named InnerClassExample and inside it, we have defined another class named InnerClass. Inside this class, we have created a toString method which return the string to its object.









Related Tutorials/Questions & Answers:
Java InnerClass
Java InnerClass   How can we use Inner Class in java program?   public class InnerClassExample{ class InnerClass{ String name...(); } } public InnerClassExample(){ InnerClass innerClass = new InnerClass
innerclass and database - Java Beginners
innerclass and database  program using innerclass to implement numerical bisection operation to call a procedure to store and update data in a database
Advertisements
Java nested class example
Java nested class example  Give me any example of Nested Class.  ... Class"; //NestedClass instance variable InnerClass innerClass = new InnerClass(); void getOuterS(){ System.out.println(outer); } void
java - Java Interview Questions
java  1.what is the diffrence between length and length()? 2.write aprogram by using static block? 3can interface have an innerclass
SCJP Module-3 Question-8
InnerClass(); } OuterClass() { System.out.print(s); } class InnerClass { String s = "InnerClass"; InnerClass() { System.out.print(s... compile error. 2. Prints : OuterClass InnerClass 3. Prints : OuterClass 4
SCJP Module-3 Question-2
[] args) { 3 OuterClass.InnerClass i = new OuterClass.new InnerClass(); 4... OuterClass { 8 public int x = 9; 9 public OuterClass() { 10 InnerClass inner = new InnerClass(); 11 inner.innerMethod(); } 12 class InnerClass { 13 public
Inner class in java
Inner class in java In this example we will describe inner classes in java.... Inner classes provides an graceful and powerful feature to the Java. Inner..._TO_REPLACE_2 Local classes:- This class is defined within a block of Java code
Java Nested Class
Java Nested Class         In Java programming language, when a class is defined within another... of Java that is included in jdk1.1. The reasons of why we use nested classes
inner class - Java Interview Questions
Java Inner Class  How many classes we can create in an inner class... to the requirement there is no limit . In Java programming language, when a class is defined... are a feature of Java that is included in jdk1.1. The reasons of why we use
SCJP Module-3 Question-1
; 6 public OuterClass() { 7 InnerClass inner = new InnerClass(); 8 inner.innerMethod(); } 9   class InnerClass { 10 public void innerMethod
Inner Class - Java Beginners
, it will generate two classes, Outer.class & Outer$Inner.class. But If I change the access
Core Java Interview Question, Interview Question
Core Java Interview Question Page 30       Objects and Classes Question: What's... Answer: To reference it you will have to use OuterClass$InnerClass Question: Can
Use of Local Inner class
;  The Java language enables you to define a class inside another... the even indices of the array. The inner class Get Even Integer is same as Java...;InnerClass() { for (int i = 0; i < size
Nested class
classes are a feature of Java that is included in jdk1.1. The reasons of why we use... StaticNestedClass { ... } class InnerClass
While and do-while
; Nested classes Here is another advantage of the Java, object... StaticNestedClass { ... } class InnerClass { ... } } i...: class OuterClass {   ...   class InnerClass {  
java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
SCJP Module-3 Question-3
Given a sample code: class OuterClass { private int x = 2; OuterClass() { outerMethod(); } public static class InnerClass { private int x = 1; public void innerMethod() { System.out.println("inner x is " + x
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  is java purely object oriented language
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java   difference between class and interface
Java
Java  how to draw class diagrams in java
java
java  write a java program using filenotfoundexception

Ads