File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
inner class ?!
Hychin
Greenhorn
Joined: Mar 25, 2002
Posts: 4
posted
Mar 27, 2002 07:18:00
0
class A {
public A (B b) {}
}
class B {
class Inner {
public void function () {
A a = new A(?); // How to create object a
...
}
}
}
John Williamer
Greenhorn
Joined: Mar 27, 2002
Posts: 23
posted
Mar 27, 2002 08:33:00
0
I'm not sure if this is what your after but here goes:
class A {
public A (B b) {}
public A (){}
}
class B {
B h=(B) this;
class Inner {
public void function () {
A a = new A(h); // How to create object a
}
}
}
Hope this helps
alex earnshaw
Ranch Hand
Joined: Nov 05, 2001
Posts: 60
posted
Mar 27, 2002 11:05:00
0
You can also use B.this directly to access the current instance of the outer class.
public class InnerDemo { public static void main(String[] args) { B myB = new B(); } } class A { public A (B b) { System.out.println("Creating A"); } } class B { public B () { System.out.println("Creating B"); Inner i = new Inner(); i.function(); } class Inner { public void function () { System.out.println("In Inner.function()"); A a = new A(B.this); // How to create object a } } }
Alex
Hychin
Greenhorn
Joined: Mar 25, 2002
Posts: 4
posted
Mar 27, 2002 17:37:00
0
thanks, alex
A a = new A(B.this); // works well and convenient
I agree. Here's the link:
http://aspose.com/file-tools
subject: inner class ?!
Similar Threads
Top-level classes
Inner class
Inner Classes
"inner class"
inner class shadowing
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter