javalearing.blogspot.com
Here we will show u a simple program of packages and its implementation.
first create a package naming pack(any name)then create class and its method should be static and public as shown below:
package pack;
public class hemant
{
public static void show(String s)
{
System.out.println(s);
}
}
save above as hemant.java
now compile your file as: javac hemant.java
now make another file in which you wanted to import your package for example demo.java
import pack.hemant; //for importing package pack having class name hemant
class demo
{
public static void main(String args[])
{
hemant.show("hi bye");
}
}
save above as demo.java
compile your package class first: javac hemant.java
compile your another file create by you: javac demo.java
run your demo file:java demo
output:
hi bye
finally you get the clear concept of packages.
Here we will show u a simple program of packages and its implementation.
first create a package naming pack(any name)then create class and its method should be static and public as shown below:
package pack;
public class hemant
{
public static void show(String s)
{
System.out.println(s);
}
}
save above as hemant.java
now compile your file as: javac hemant.java
now make another file in which you wanted to import your package for example demo.java
import pack.hemant; //for importing package pack having class name hemant
class demo
{
public static void main(String args[])
{
hemant.show("hi bye");
}
}
save above as demo.java
compile your package class first: javac hemant.java
compile your another file create by you: javac demo.java
run your demo file:java demo
output:
hi bye
finally you get the clear concept of packages.
No comments:
Post a Comment