Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Programmer Certification (OCPJP)
inner class ?!
Hychin
Greenhorn
Posts: 4
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 23
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 60
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 4
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks, alex
A a = new A(B.this); // works well and convenient
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
"inner class"
Inner Classes
Inner class
inner class shadowing
Top-level classes
More...