step 1:
path ="D:\javaprogram"
code under directory "D:\javaprogram" :
package javaprogram;
public class p1
{
public void print()
{
System.out.println("asdfg");
}
}
step 2: compile:
C:\Users\user>d:
D:\>cd javaprogram
D:\javaprogram>javac p1.java
D:\javaprogram>
step3: go to parent directory
D:\javaprogram>cd ..
D:\>
step4 : create p2.java under directory "d:"
step5 (optional) : for checking , if package is created or not ( if main() is present in p1 class)
D:\>java javaprogram.p1 ( if main() is not present , it will get an error)
step 6: code of p2.java
import javaprogram.p1;
public class p2 extends p1
{
public static void main(String args[])
{
p2 ob =new p2();
ob.print();// print function from p1 (package javaprogram)
}
}
path ="D:\javaprogram"
code under directory "D:\javaprogram" :
package javaprogram;
public class p1
{
public void print()
{
System.out.println("asdfg");
}
}
step 2: compile:
C:\Users\user>d:
D:\>cd javaprogram
D:\javaprogram>javac p1.java
D:\javaprogram>
step3: go to parent directory
D:\javaprogram>cd ..
D:\>
step4 : create p2.java under directory "d:"
step5 (optional) : for checking , if package is created or not ( if main() is present in p1 class)
D:\>java javaprogram.p1 ( if main() is not present , it will get an error)
step 6: code of p2.java
import javaprogram.p1;
public class p2 extends p1
{
public static void main(String args[])
{
p2 ob =new p2();
ob.print();// print function from p1 (package javaprogram)
}
}
step 7: compile p2.java
D:\>javac p2.java
step 8: execute p2
D:\>java p2
asdfg
D:\>
No comments:
Post a Comment