I need help on java modifiers, pls.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mayfjf
    New Member
    • Jan 2007
    • 14

    #1

    I need help on java modifiers, pls.

    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.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mayfjf
    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?

    Comment

    • hirak1984
      Contributor
      • Jan 2007
      • 316

      #3
      the best way to learn about them is to use them in your code and see the results(i mean errors).

      Comment

      • mayfjf
        New Member
        • Jan 2007
        • 14

        #4
        Originally posted by r035198x
        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?

        Comment

        • mayfjf
          New Member
          • Jan 2007
          • 14

          #5
          Originally posted by hirak1984
          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!

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            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?
            Well this introduce you to these quickly.

            Comment

            • hirak1984
              Contributor
              • Jan 2007
              • 316

              #7
              In reply to ur confusion regarding "static" before main==>
              The JVM is designed such a way that it always finds the function
              Code:
              public static void main(String a[])
              to start with.
              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
              Code:
              public class Main {
              public  static void main1(String args[])
              {
              	System.out.println("here");
              }
              }
              or this code:
              Code:
              public class Main {
              public   void main(String args[])
              {
              	System.out.println("here");
              }
              }

              Comment

              Working...