• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we create a Inner Class for a INNER Class?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have one doubt regarding Inner class... This is different than the other topic though... Can I create an Inner Class for a INNER class?? what will happen if I create and what is the use of it???
 
Ranch Hand
Posts: 225
Spring Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,you can.



Regards
Baseet Ahmed
 
Justin Smith
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Baseet,

I tried creating one and was able to create it, but i wish to know is there any real world scenario which would need a scenario like this???

Here is my sample program....


import java.util.*;
import java.lang.*;

public class MyOuter implements java.io.Serializable
{
private int x = 6;
private String name = "Humpty Dumpty";
public MyOuter(){System.out.println("Calling the Outermost Constructor");}
public MyOuter(String arg){}
public double seeCurrent()
{
float f = 3.1416f;
Double d = Double.valueOf(f*x);
return d;
}
class MyInner
{
public MyInner(){System.out.println("Calling the MyInner Constructor");}
public void seeOuter()
{
System.out.println("The value of the 'x' is :"+x);
}
class MyInnerMost extends java.lang.Thread
{
public MyInnerMost(){System.out.println("Calling the MyInnerMost Constructor");}
public void seeOuterMost()
{
System.out.println("The 'name' selected for $1 million dollar is:"+name);
}
}
}

public static void main(String[] are)
{
System.out.println("Before creating any instance in the main method");
Double value = null;
MyOuter mo = new MyOuter();
value = mo.seeCurrent();
System.out.println("The value of the return value is :"+value);
MyOuter.MyInner mi = new MyOuter().new MyInner();
mi.seeOuter();
MyOuter.MyInner.MyInnerMost mim = new MyOuter().new MyInner().new MyInnerMost();
mim.seeOuterMost();
}
}

The output is :
---------------

The value of the return value is :18
Calling the Outermost Constructor
Calling the MyInner Constructor
The value of the 'x' is :6
Calling the Outermost Constructor
Calling the MyInner Constructor
Calling the MyInnerMost Constructor
The 'name' selected for $1 million d
Press any key to continue . . .
 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure! you can do so.But as you observe, this programming practice is a sort of obfuscating the logic.Even you can do various other combinations with method-local/argument specific local classes(and their sub-classes).

In actual programming development if you feel the need, you should reconsider your design/programming practice(well I am not sure here).Mainly we need inner classes to handle event driven logic in GUI but other than that, OOP in my opinion eliminates this need for code cluttering/repetitive logic.
 
Justin Smith
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sumeet,

Thanks for your reply !!!
reply
    Bookmark Topic Watch Topic
  • New Topic