• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Inner classes

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain how to create a new object of type iopgf.
class f{
static class j{
static class iop{
class iopgf{
public void test(){
System.out.println ("I am here");
}
}
}
}
public static void main(String args[]){
f.j.iop.iopgf y=new f.j.iop.iopgf();\\not working

}

}
 
Ranch Hand
Posts: 5397
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to find out why previously it was not running ?? if you don't get then please ask again.
Key point is that enclosing class's object should be there in order to create inner class.

[ April 11, 2002: Message edited by: Ravish Kumar ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even this works..
class f{
static class j{
static class iop{
class iopgf{
public void test(){
System.out.println ("I am here");
}
}
}
}
public static void main(String args[]){
f.j.iop.iopgf y=new f().new j().new iop().new iopgf();// working
}
}
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravish,
A bit doubt here. Why is the following not compiled? I thought a non-static inner class needs an instantiation of the outer class, thus the line " new iop() ". But it only works for "iop()" without the keyword new.
f.j.iop.iopgf z = new f.j.new iop().new iopgf();//NOT WORKING
f.j.iop.iopgf z = new f.j.iop().new iopgf();//WORKING
Clement
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why doesn't thiw work ravish?
class f{
static class j{
static class iop{
class iopgf{
public void test(){
System.out.println ("I am here");
}
}
}
}
public static void main(String args[]){
f.j.iop.iopgf y=f.j.new iop().new iopgf();//notworking
}
}
 
Steven Wong
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answers from anyone?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
f.j.iop.iopgf y=f.j.new iop().new iopgf()
will not compile because
(i) no new after "="
(ii) no braces after f.j
the following compiles:
f.j.iop.iopgf y=new f.j().new iop().new iopgf()
[ April 16, 2002: Message edited by: Rolf Weasel ]
 
R K Singh
Ranch Hand
Posts: 5397
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by codehouse:
why doesn't thiw work ravish?
f.j.iop.iopgf y=f.j.new iop().new iopgf();//notworking


Hi codehouse
first change your name as per ranch policy. dummy name u can use in MD (even no need to register)
Now can you tell me why it should work.. joking
AW now can you tell me what is the use of f.j. here in this statement? ... seriously
suppose I have a class mypack01.mypack02.MyClass
Can I create an instance of MyClass like this?
mypack01.mypack02.MyClass mc = mypack01.mypack02.new MyClass();
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic