packages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hostel
    New Member
    • Feb 2007
    • 17

    packages

    how to compile different java source files ( h1.java , h2 .java , h3.java and demo.java) defined under same package(test) ;
    demo.java contains main() method.
    h1 contains some public , private , protected data.
    h2 extends h1
    h3 in the same package ( not subclass of either h1 or h2) ;

    when i compiled h1( no error) , but when compiled h2( got error)

    plz help.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by hostel
    how to compile different java source files ( h1.java , h2 .java , h3.java and demo.java) defined under same package(test) ;
    demo.java contains main() method.
    h1 contains some public , private , protected data.
    h2 extends h1
    h3 in the same package ( not subclass of either h1 or h2) ;

    when i compiled h1( no error) , but when compiled h2( got error)

    plz help.
    Compile the ones that do not deepend on others first. If you still get errors then you need to post the error messages you are getting.

    Comment

    • hostel
      New Member
      • Feb 2007
      • 17

      #3
      // file named h1.java
      package demo;
      public class h1
      {
      public int a=10;
      }

      //file named h2.java
      package demo;
      class h2 extends h1
      {
      h2()
      {
      System.out.prin tln("a="+a);
      }
      }

      error
      "can't find symbol"
      symbol : a

      Comment

      • SrikanthPrithvi
        New Member
        • May 2007
        • 5

        #4
        Hi Hostel check this out,
        -------------------------------------------------------
        // h1.java
        package demo;

        public class h1 {
        public int a = 10;
        }
        -------------------------------------------------------
        // h2.java

        package demo;

        import demo.h1;

        public class h2 extends h1 {
        h2() {
        System.out.prin tln("a = "+a);
        }
        }
        -------------------------------------------------------

        and compile as "javac demo\h2.java"
        this doesn't produces any error.

        Comment

        Working...