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.
I need help on java modifiers, pls.
Collapse
X
-
Ok let's have what you think about them first. What did you understand so far?Originally posted by mayfjf1.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. -
...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?Originally posted by r035198xOk let's have what you think about them first. What did you understand so far?
...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?Comment
-
Well this introduce you to these quickly.Originally posted by mayfjf...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?Comment
-
In reply to ur confusion regarding "static" before main==>
The JVM is designed such a way that it always finds the function
to start with.Code:public static void main(String a[])
the keyword static means that the function following needs no "instantiat ion"
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
or this code:Code:public class Main { public static void main1(String args[]) { System.out.println("here"); } }
Code:public class Main { public void main(String args[]) { System.out.println("here"); } }Comment
Comment