package
how to create one package inside another package.i.e., i hav created folder of package1,inside package1 i created another package say package2 in package2 i defined some methods under the class class_example.So how to import that particular class class_example which is under package2
here is the question
3. Implement two packages in the following manner:
Package2 should be inside Package1 and we have to define methods in a class called class_example in package2. This class is required to be imported in our main class using the below import statement:
import package1.package2.class_example;
I have coded in following manner in this flow
D:\Java Project Modules\package
package1 -->package2-->class_example.java which is like this
package package2;
public class Class_example
{
public void PrintName ( ) {
System.out.println ("\nMy name is Harini.J!");
}
public void PrintAge ( ) {
System.out.println ("\n My Age is 21 year Old");
}
}
so how to import this particular class only.I am getting error like file does not exist.
main method looks like this which i hav coded
import package1.package2.Class_example;
public class Myexample
{
public static void main(String[] args)
{
Class_example ce=new Class_example();
ce.PrintName();
ce.PrintAge();
}
}
please kindly help me out