Java Packages – Tutorial 4

1. Expalin Package and what is need of package.

2. Creating Package.

/*

Code:

*/

package com.vinod;

public class Student {

private int id;
private String name;

public Student()
{
id=0;
name=null;
}
public Student(int tid,String tname)
{
id=tid;
name=tname;
}

public void setData()
{
id=0;
name=null;
}

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
System.out.println(“\n ID is:”+id);
System.out.println(“\n Name is:”+name);
}
}

package com.second;

public class Employee {

private int id;
private String name;

public void setData(int tid, String tname) {
id = tid;
name = tname;
}

public void display() {
System.out.println(“\nEmployee ID is:” + id);
System.out.println(“\nEmpoyee Name is:” + name);
}
}

package com.vinod;

import com.second.*;

public class MainClass {

public static void main(String[] args) {

Student stu1=new Student();
stu1.setData(1,”Vinod Pillai”);
stu1.display();

Student stu2=new Student(2,”Abc User”); //Calling Constructor with argument.
stu2.display();

Employee emp1=new Employee();
emp1.setData(101, “Ramesh”);
emp1.display();

com.second.Employee emp2=new com.second.Employee();
emp2.setData(102, “Xyz”);
emp2.display();
}
}

http://www.youtube.com/vinodthebest

Advertisements

1 Comment

Filed under General

One response to “Java Packages – Tutorial 4

  1. You can definitely see your enthusiasm in the work you write. The sector hopes for even more passionate writers such as you who are not afraid to say how they believe. All the time go after your heart.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s