Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Java in General
Nested class - instantiation
Shivani Chandna
,
Ranch Hand
Jul 30, 2005 10:02:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
How to instantiate the class Inner extending StInner . Its giving error if i try in the below ways?
///code package nt; public class TestWait{ int z =45; public static void main(String[] args) { System.out.print("dd"); TestWait tt = new TestWait(); TestWait.StInner in3 = new TestWait.StInner();//.Inner(); /**Error in below two statements**/ TestWait.StInner.Inner in34 = new TestWait.StInner().Inner(); TestWait.StInner.Inner in34 = new tt.StInner().Inner(); } public static class StInner{ int z = 54; class Inner extends StInner { int z = 554; public void getter() { System.out.print(Inner.this.z); System.out.print(StInner.this.z); } } } }
Regards.
Ilja Preuss
,
author
staff
Jul 30, 2005 11:13:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Because Inner is not static, it needs to be bound to an instance of the enclosing class (StInner).
If you want to make that in3, the following should work (this is from memory, so no warranty):
TestWait.StInner.Inner in34 = in3.new Inner();
Post by:
autobot
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 549 times.
Similar Threads
inner static class
Converting into Arrays
Interaction between threads
Inner class Doubts
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:23:35
.