Skip to content

Instantly share code, notes, and snippets.

@kenorb
Last active August 29, 2015 14:04
Show Gist options
  • Save kenorb/f402fd9b6e590b213df6 to your computer and use it in GitHub Desktop.
Save kenorb/f402fd9b6e590b213df6 to your computer and use it in GitHub Desktop.
Student.java - Package Demo
/*
* Student.java - Package Demo
*
* - A package acts as a container which holds .class files.
* - Packages avoid the namespace collisions between the classes.
* - Once a package is created, it can be re-used or imported to any source code.
* - A package can be created using a package statement: package package_name.
*
* Usage:
* javac -d . Student.java
*
* It creates a directory structure (p1-->p2-->p3).
*/
package p1.p2.p3;
public class Student {
private int id;
private String name;
private String course;
public Student() {
id = 1000;
name = "Krish";
course = "OCP";
}
public void getStudent() {
System.out.println(id + " " + name + " " + course);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment