i want to diiscus my dobut with u.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 52
Reputation: ajay_tabbu is an unknown quantity at this point 
Solved Threads: 0
ajay_tabbu's Avatar
ajay_tabbu ajay_tabbu is offline Offline
Junior Poster in Training

i want to diiscus my dobut with u.

 
0
  #1
Mar 6th, 2007
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
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: i want to diiscus my dobut with u.

 
0
  #2
Mar 7th, 2007
be more precise in your language use. Your writings are completely incomprehensible due to the volume of incorrect grammar and spelling.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 52
Reputation: ajay_tabbu is an unknown quantity at this point 
Solved Threads: 0
ajay_tabbu's Avatar
ajay_tabbu ajay_tabbu is offline Offline
Junior Poster in Training

Re: i want to diiscus my dobut with u.

 
0
  #3
Mar 7th, 2007
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.
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 137
Reputation: PoovenM is on a distinguished road 
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Re: i want to diiscus my dobut with u.

 
1
  #4
Mar 7th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 52
Reputation: ajay_tabbu is an unknown quantity at this point 
Solved Threads: 0
ajay_tabbu's Avatar
ajay_tabbu ajay_tabbu is offline Offline
Junior Poster in Training

Re: i want to diiscus my dobut with u.

 
0
  #5
Mar 7th, 2007
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.
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 137
Reputation: PoovenM is on a distinguished road 
Solved Threads: 11
PoovenM PoovenM is offline Offline
Junior Poster

Re: i want to diiscus my dobut with u.

 
0
  #6
Mar 7th, 2007
  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: i want to diiscus my dobut with u.

 
0
  #7
Mar 8th, 2007
Originally Posted by ajay_tabbu View Post
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:

  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. }

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:

  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...
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: i want to diiscus my dobut with u.

 
0
  #8
Mar 8th, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC