943,871 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1930
  • Java RSS
Mar 6th, 2007
0

i want to diiscus my dobut with u.

Expand Post »
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
Reputation Points: 24
Solved Threads: 0
Junior Poster in Training
ajay_tabbu is offline Offline
52 posts
since Feb 2007
Mar 7th, 2007
0

Re: i want to diiscus my dobut with u.

be more precise in your language use. Your writings are completely incomprehensible due to the volume of incorrect grammar and spelling.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 7th, 2007
0

Re: i want to diiscus my dobut with u.

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.
Reputation Points: 24
Solved Threads: 0
Junior Poster in Training
ajay_tabbu is offline Offline
52 posts
since Feb 2007
Mar 7th, 2007
1

Re: i want to diiscus my dobut with u.

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
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Mar 7th, 2007
0

Re: i want to diiscus my dobut with u.

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.
Reputation Points: 24
Solved Threads: 0
Junior Poster in Training
ajay_tabbu is offline Offline
52 posts
since Feb 2007
Mar 7th, 2007
0

Re: i want to diiscus my dobut with u.

Java Syntax (Toggle Plain Text)
  1. public class Outer {
  2. int instanceVariableOne;
  3. private class Inner {
  4. int a, b;
  5. public Inner(int x, int y)
  6. {
  7. instanceVariableOne = x;
  8. a = x * 2;
  9. instanceVariableTwo = y;
  10. b = y * 2;
  11. }
  12. }
  13. int instanceVariableTwo;
  14.  
  15. public Outer()
  16. {
  17. Inner test = new Inner(1, 2);
  18. System.out.println("a from Inner\tb from Outer\n" + test.a + "\t\t\t\t" + test.b);
  19. System.out.println("\nOne\tTwo");
  20. System.out.println(instanceVariableOne + "\t" + instanceVariableTwo);
  21. }
  22.  
  23. public static void main(String[]args)
  24. {
  25. new Outer();
  26. }
  27. }

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
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Mar 8th, 2007
0

Re: i want to diiscus my dobut with u.

Click to Expand / Collapse  Quote originally posted by ajay_tabbu ...
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.
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:

java Syntax (Toggle Plain Text)
  1. public class Temp
  2. {
  3. public static class Inner
  4. {
  5. private int temp_ ;
  6.  
  7. public Inner ( int temp )
  8. {
  9. temp_ = temp ;
  10. }
  11.  
  12. public Inner ( )
  13. {
  14. temp_ = 100 ;
  15. }
  16.  
  17. public void main (String args [])
  18. {
  19. System.out.print ( "Helo Inner" ) ;
  20. }
  21.  
  22. public int getValue ( )
  23. {
  24. return temp_ ;
  25. }
  26. }
  27.  
  28. public static void main (String args [])
  29. {
  30. Inner var1 = new Inner ( ) ;
  31. System.out.println ( var1.getValue ( ) ) ;
  32.  
  33. Inner var2 = new Inner ( 999 ) ;
  34. System.out.println ( var2.getValue ( ) ) ;
  35.  
  36. System.out.println ( "Helo" ) ;
  37. }
  38. }

Quote ...
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.
You as such can't make your inner classes as the "main" class since inner classes can't have static declarations. The moment you try to do this the compiler will throw the above error. Take a look at this code:

java Syntax (Toggle Plain Text)
  1. // Temp.java
  2.  
  3. class A // you can't declare this as public since my filename is "Temp.java"
  4. {
  5. public static void main ( String[] args ) // won't be called since the main of only the
  6. { // public class with name same as file name will
  7. // be called
  8. System.out.print ( "Hello my friend" ) ;
  9. }
  10.  
  11. public class Temp // inner class can never be the main class
  12. {
  13. private int temp_ ;
  14.  
  15. public static void main ( String[] args ) // error !!!
  16. {
  17. System.out.print ( "Hello my friend" ) ;
  18. }
  19.  
  20. public Temp ( )
  21. {
  22. temp_ = 0 ;
  23. }
  24.  
  25. public Temp ( int temp )
  26. {
  27. temp_ = temp ;
  28. }
  29. }
  30. }

Oh and btw, those were good questions...
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Mar 8th, 2007
0

Re: i want to diiscus my dobut with u.

Quote ...
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:
Not quite. In fact it's only mandatory when creating an instance from within a static method of the outer class.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Showing data in neat and tidy
Next Thread in Java Forum Timeline: RAD tool





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC