SIVA

SIVA

  • NA
  • 742
  • 707.4k

How to import packages in java

Jan 2 2012 3:33 PM
Hi All,
I have one doubt regarding Java.
I have 2 packages in java. In that i have imported one package into another
as follows.


package package1;
public class Base1{
public void Method1(){
System.out.println("Method1");
}
}

package package2;
import package1;
public class Base2{
public void Method2(){
System.out.println("Method2");
Base1 b1=new Base1();
b1.Method1();
}
}


import package2;
public class clsMain{
public static void main(String[] args){
Base2 b2=new Base2();
b2.Method2();
}
}



Can any body tell me this
its showing some errors as follows
while compiling the second file Base2 the following error is coming

Base2.java:2: '.' expect
import Package1;


and While compiling the clsMain file its showing following errors

clsMain.java:1: package package2 does not exist
import package.*;
^
.\Base21.java:2: '.' expected
import Package1;
^
Use.java:9: cannot access Base2
bad class file: .\Base2.java
file does not contain class Base2
Please remove or make sure it appears in
th.
Base2 m = new Base2();


If anything wrong is there in this can you give code for this scenario please

Answers (1)