By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

I need help on java modifiers, pls.

mayfjf
P: 14
1.Hello, I wonder what are the differences between modifiers? Private, public, default, static...? I have reread and reread my java book, but I just can't understand.
Jan 30 '07 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
1.Hello, I wonder what are the differences between modifiers? Private, public, default, static...? I have reread and reread my java book, but I just can't understand.
Ok let's have what you think about them first. What did you understand so far?
Jan 30 '07 #2

hirak1984
100+
P: 316
the best way to learn about them is to use them in your code and see the results(i mean errors).
Jan 30 '07 #3

mayfjf
P: 14
Ok let's have what you think about them first. What did you understand so far?
...that when a method is static, you cannot change it outside the class. But why is it that the values of variables inside the main( ) can still be changed even if main( ) is declared as static?

...that a public class can be accessed by classes that belong to the other package. Is package related to group? I have not yet developed several program that exist in the same package.

... that if a class uses a default modifer, then only classes on the same package where it belongs, can access that class.

... that if a class has no defined modifier, does it mean it uses a default modifier?
Jan 30 '07 #4

mayfjf
P: 14
the best way to learn about them is to use them in your code and see the results(i mean errors).
yeah, your right... I will try. Thanks!
Jan 30 '07 #5

10K+
P: 13,264
...that when a method is static, you cannot change it outside the class. But why is it that the values of variables inside the main( ) can still be changed even if main( ) is declared as static?

...that a public class can be accessed by classes that belong to the other package. Is package related to group? I have not yet developed several program that exist in the same package.

... that if a class uses a default modifer, then only classes on the same package where it belongs, can access that class.

... that if a class has no defined modifier, does it mean it uses a default modifier?
Well this introduce you to these quickly.
Jan 30 '07 #6

hirak1984
100+
P: 316
In reply to ur confusion regarding "static" before main==>
The JVM is designed such a way that it always finds the function
Expand|Select|Wrap|Line Numbers
  1. public static void main(String a[])
to start with.
the keyword static means that the function following needs no "instantiation"
means it dont need any other method to call it for execution.
If this system was not there then u cudnt have run any java program.
just try to run the following
Expand|Select|Wrap|Line Numbers
  1. public class Main {
  2. public  static void main1(String args[])
  3. {
  4.     System.out.println("here");
  5. }
  6. }
or this code:
Expand|Select|Wrap|Line Numbers
  1. public class Main {
  2. public   void main(String args[])
  3. {
  4.     System.out.println("here");
  5. }
  6. }
Jan 30 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.