Tutoriallearn.com

Easy Learning


Home

Search Tutoriallearn.com :



Java Package

  • Package :- It is used to group similar classes or other related resources in th folder.
  • Package concept is similar to folder concepts of window. For each package, respective folder must be created.
  • For example, if you want to create a package named "institute". You need to write the sentence in the program: package institute;
  • Accordingly, a folder named "institute" must be created in current director.

Example

package institute;

class student {
	int rollno;
	String name;
	void setdata(int rl, String nm)
	{
		rollno = rl;
		name = nm;
	}
     void getdata()
	{
		System.out.println("Roll no is " + rollno);
		System.out.println ("Name is " + name);
	}
}

class demopackage {
	public static void main (String args[] )
	{
           stduent obj1 = new student();
            obj1.setdata(123,"Amit");
	    obj1.getdata();
	}

}

Output of the program

Roll no 123
Name is Amit


© Copyright 2016-2025 by tutoriallearn.com. All Rights Reserved.