| | |
i want to diiscus my dobut with u.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
i have some dobut i will be oblise if u will help me
my doubt is that can we make one class into another class n if it is posible than happend in folling case.
1 if i have nested calss then can i call method of iner most calss in outer most calss or can i do visvarsa.
2 what happend if i make outer class as public static void main(String a[ ]
3 what happend if i make outer most class in as public satatic void main (String a[]
i also want to do this problem by my oue but i have one problem i was using XP but due to viruses i fedup n i instole linux i never use linux before so i face many problems in instoling linux but i do it.n now i m working in linux but i can't instole it properly so i m facing probliems but still i want to work in linux so can u tell me how i can instole java in linux n how n where can i write my code .n also how i can compile n run that. due to this problem i cant do my practis.so i m looking for u r grat spourt plz guid me.i have also post some of my problems related to linux in from of this site i.t.
TECH TALK>LINUX AND UINX>I
my doubt is that can we make one class into another class n if it is posible than happend in folling case.
1 if i have nested calss then can i call method of iner most calss in outer most calss or can i do visvarsa.
2 what happend if i make outer class as public static void main(String a[ ]
3 what happend if i make outer most class in as public satatic void main (String a[]
i also want to do this problem by my oue but i have one problem i was using XP but due to viruses i fedup n i instole linux i never use linux before so i face many problems in instoling linux but i do it.n now i m working in linux but i can't instole it properly so i m facing probliems but still i want to work in linux so can u tell me how i can instole java in linux n how n where can i write my code .n also how i can compile n run that. due to this problem i cant do my practis.so i m looking for u r grat spourt plz guid me.i have also post some of my problems related to linux in from of this site i.t.
TECH TALK>LINUX AND UINX>I
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
thanks for telling me this fact but my english is not good but i m working hard to improve it hope soon i will improve my language.again thanks for u r spout me to improv me.
plz tell me what ever i have posted in that u can understudied my problem or not if u can't then i will post that again in some batter way.
plz tell me what ever i have posted in that u can understudied my problem or not if u can't then i will post that again in some batter way.
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
•
•
Join Date: Aug 2006
Posts: 137
Reputation:
Solved Threads: 11
It's perfectly acceptable to have an inner class. You'll be able to access all the methods and instance variables of the inner class in your outer class. Now I'm not too sure about the reverse. I think that you'll be able to access all instance methods of the outer class in the inner class if they are declared above the inner class... now I also remember that things like that aren't an issue in Java so perhaps I'm mistaken.
I didn't quite understand points 2 and 3 I'm afraid.
Yes you can install Java on Linux... there are various ways to do it. Most Linux flavors come with Java support. Federa actually has Eclipse in it though I'm still a strong fan of Suse Linux
Well hope that helps.. I'll try the inner and outer class things and post a more certain reply if you don't get another.
Peace
I didn't quite understand points 2 and 3 I'm afraid.
Yes you can install Java on Linux... there are various ways to do it. Most Linux flavors come with Java support. Federa actually has Eclipse in it though I'm still a strong fan of Suse Linux

Well hope that helps.. I'll try the inner and outer class things and post a more certain reply if you don't get another.
Peace
2nd ponit is that if i if make any class as main class by public static void main then all the method of that class become static so in case of inner class if i make outer class as the main class then what happend with inner classes wether that class also become satatic or not.
3rd point is revers case of second that is waht happend if i make inner most class as main class then what happend with outer classes wether they become static or not.
3rd point is revers case of second that is waht happend if i make inner most class as main class then what happend with outer classes wether they become static or not.
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
•
•
Join Date: Aug 2006
Posts: 137
Reputation:
Solved Threads: 11
Java Syntax (Toggle Plain Text)
public class Outer { int instanceVariableOne; private class Inner { int a, b; public Inner(int x, int y) { instanceVariableOne = x; a = x * 2; instanceVariableTwo = y; b = y * 2; } } int instanceVariableTwo; public Outer() { Inner test = new Inner(1, 2); System.out.println("a from Inner\tb from Outer\n" + test.a + "\t\t\t\t" + test.b); System.out.println("\nOne\tTwo"); System.out.println(instanceVariableOne + "\t" + instanceVariableTwo); } public static void main(String[]args) { new Outer(); } }
Hi, so I tested it out using the above code (which does nothing useful). It makes perfect sense and I can't believe I wasn't sure! What ever is declared within the same braces as your inner class will be accessible by the inner class regardless if it's declared private or public. The braces specify a scope. If something was declared in say the constructor of your outer class then it obviously won't be visible to the inner class - simply because anything delcared in a method is only visible in that method.
The inner class is always accessible to the outer class! If you declare the inner class private then it will not be accessible via a Outer class object though.
Oh and btw If you go to the Java site they give you instructions about setting it up with Linux
•
•
•
•
2nd ponit is that if i if make any class as main class by public static void main then all the method of that class become static so in case of inner class if i make outer class as the main class then what happend with inner classes wether that class also become satatic or not.
But if you need to create instances of inner class, 'static' qualifier is the must:
java Syntax (Toggle Plain Text)
public class Temp { public static class Inner { private int temp_ ; public Inner ( int temp ) { temp_ = temp ; } public Inner ( ) { temp_ = 100 ; } public void main (String args []) { System.out.print ( "Helo Inner" ) ; } public int getValue ( ) { return temp_ ; } } public static void main (String args []) { Inner var1 = new Inner ( ) ; System.out.println ( var1.getValue ( ) ) ; Inner var2 = new Inner ( 999 ) ; System.out.println ( var2.getValue ( ) ) ; System.out.println ( "Helo" ) ; } }
•
•
•
•
3rd point is revers case of second that is waht happend if i make inner most class as main class then what happend with outer classes wether they become static or not.
java Syntax (Toggle Plain Text)
// Temp.java class A // you can't declare this as public since my filename is "Temp.java" { public static void main ( String[] args ) // won't be called since the main of only the { // public class with name same as file name will // be called System.out.print ( "Hello my friend" ) ; } public class Temp // inner class can never be the main class { private int temp_ ; public static void main ( String[] args ) // error !!! { System.out.print ( "Hello my friend" ) ; } public Temp ( ) { temp_ = 0 ; } public Temp ( int temp ) { temp_ = temp ; } } }
Oh and btw, those were good questions...
I don't accept change; I don't deserve to live.
•
•
•
•
It is not as such compulsory to make the inner class as 'static' unless you plan on creating instances of that class in the 'outer class'.
But if you need to create instances of inner class, 'static' qualifier is the must:
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Other Threads in the Java Forum
- Previous Thread: Showing data in neat and tidy
- Next Thread: RAD tool
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working






