Java Package Problem [Click Here]

Number of replies: 24

Define a package named "MyPack" and create class "person" inside this package. Person class has two properties ID and name which are private. You have to create another package "Pack" where you have a class Employee which want to use the person two properties ID and name. Will the "pack" package can call them?

Write the program and explain.

In reply to First post

Re: Java Package Problem [Click Here]

by Md. Alif Sheakh -

package MyPack;

public class person {
private String ID = "201-15-3292";
private String name = "MD. Alif Sheakh";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

So, "Pack" package can't call them(MyPack.person). Because the properties of the person in "MyPack" Package are in private form which is why we cannot call it in the "Pack" package, but if we make the personal properties public then we can call it on "Pack" package. 

We can't call it another package, mainly because the properties are private. However, private properties can be called in their own package

In reply to First post

Re: Java Package Problem [Click Here]

by Md. Jahidul Islam (201-15-3368) -
package MyPack;
public class person {
private String ID = "201-15-3368";
private String name = "Md. Jahidul Islam Jahid";
}
package Pack;
import MyPack.*;
public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

Some details:
Here we can see ‘Pack’ package can't call them (MyPack.person). So, reason is the properties of the person in "My Pack" which is a Package are in private form and that’s why we cannot call it in the ‘Pack’ package, but if we make the private assets public then we can call it "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by MD.Abdulla-Hil-Kafi (201-15-3109) -
package myPack;

public class person {
private String ID = "201-15-3109";
private String Name = "MD.Abdulla-Hil-Kafi";

}
package Pack;
import myPack.*;

public class employee {
public static void main(String[] args) {
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}
As the "myPack" package is in a private form That's why we can't call it in another package like the "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by Tasnim Bill Zannah (201-15-3033) -
package MyPack;

public class person {

private final String ID = "201-15-3033";
private final String Name = "Tasnim Bill Zannah";

}
package Pack;
import Pack.*;

public class Employee {
public static void main(String[] args) {
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}


From the above program, we can see that the "Pack" Package can't call them. Because the properties of the "MyPack" package are in private form. Unless we make the properties public we can't call them in the "Pack" Package.
In reply to First post

Re: Java Package Problem [Click Here]

by Sadia Islam Tonni(201-15-3290) -
package myPack;

public class person {
private String ID = "201-15-3290";
private String Name = "Sadia Islam Tonni";

}
package Pack;
import myPack.*;

public class employee {
public static void main(String[] args) {
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}
In reply to First post

Re: Java Package Problem [Click Here]

by Rahad Islam (201-15-3623) -
package myPack;

public class person {
private String ID = "201-15-3109";
private String Name = "MD.Abdulla-Hil-Kafi";

}
package Pack;
import myPack.*;

public class employee {
public static void main(String[] args) {
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}
In reply to First post

Re: Java Package Problem [Click Here]

by Pritom Basak (201-15-3342) -
package MyPack;

public class person {
private String ID = "201-15-3342";
private String Name = "Pritom Basak";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person o = new person();
System.out.println("Name: " + o.Name);
System.out.println("ID: " + o.ID);
}
}

The "Pack" package can not call them. Because when a package is in private form we can not call it from another package. That's why when
the "MyPack" package is in a private form we can't call it in another package like the "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by Mst.Fatematuz Zohura(201-15-3195) -
package MyPack;

public class person {
private String ID = "201-15-3195";
private String name = "Mst.Fatematuz Zohura";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person MyObj = new person();
System.out.println("Name: " + MyObj.name);
System.out.println("ID: " + MyObj.ID);
}
}

The "Pack" package can't call them(MyPack.person). Because the properties of the person in the "MyPack" Package are in a private firm which is why we cannot call it in the "Pack" package, but if we make the personal properties public then we can call it on the "Pack" package.
so, private properties can be called in their own package.
In reply to First post

Re: Java Package Problem [Click Here]

by Ieshita Nasrin Bithi (201-15-3216) -
package MyPack;

public class person
{
private String ID = "201-15-3216";
private String Name = "Ieshita Nasrin Bithi";
}
package Pack;
import MyPack.*;

public class employee
{
public static void main(String[] args)
{
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}
In reply to First post

Re: Java Package Problem [Click Here]

by Shazzad Shawon (201-15-3404) -

package MyPack;

public class person {
private String ID = "201-15-3404";
private String my_name = "Shazzad Shawon;

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person MyObj = new person();
System.out.println("Name: " + MyObj.my_name);
System.out.println("ID: " + MyObj.ID);
}
}

The "Pack" package can't call them(MyPack.person). Because the properties of the person in the "MyPack" Package are in a private firm which is why we cannot call it in the "Pack" package, but if we make the personal properties public then we can call it on the "Pack" package.
so, private properties can be called in their own package.

In reply to First post

Re: Java Package Problem [Click Here]

by Zaky Hossain (201-15-3610) -
package myPack;

public class person {
private String ID = "201-15-3109";
private String Name = "MD.Abdulla-Hil-Kafi";

}
package Pack;
import myPack.*;

public class employee {
public static void main(String[] args) {
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}
As the "myPack" package is in a private form That's why we can't call it in another package like the "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by Sadia Sultana Chowa ( 201-15-3052 ) -
package MyPack;

public class person {
private String ID;
private String Name;
public void varify(String ID, String Name) {
this.ID = ID;
this.Name = Name;
}
public String getID()
{
return ID;
}
public void setID(String ID) {
this.ID= ID;
}
public String getName()
{
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
}

package Pack;
import MyPack.*;
import java.util.Scanner;
public class Employee {

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter the ID : ");
String id = s.nextLine();
System.out.print("Enter the Name : ");
String name = s.nextLine();
person p= new person();
p.varify(id, name);
System.out.println("\nThe name is : "+p.getName());
System.out.println("The ID is : "+p.getID());
}
}

We can easily call MyPack from Pack package and can access the private values of MyPack by using the getter and setter method.
In reply to First post

Re: Java Package Problem [Click Here]

by Risul Islam Jim (201-15-3675) -
package MyPack;

public class person {
private String ID;
private String Name;
public void identify(String ID, String Name) {
this.ID = ID;
this.Name = Name;
}
public String getID()
{
return ID;
}
public void setID(String ID) {
this.ID= ID;
}
public String getName()
{
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
}
package Pack;
import MyPack.*;
import java.util.Scanner;
public class Employee {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.print("Enter the ID : ");
String id = x.nextLine();
System.out.print("Enter the Name : ");
String name = x.nextLine();
person y= new person();
y.identify(id, name);
System.out.println("\nThe name is : "+y.getName());
System.out.println("The ID is : "+y.getID());
}
}
In reply to First post

Re: Java Package Problem [Click Here]

by Mst. Sazia Tahosin (201-15-3666) -

 

package MyPack;

 

public class person {

private String ID;

private String Name;

public void varify(String ID, String Name) {

this.ID = ID;

this.Name = Name;

}

public String getID()

{

return ID;

}

public void setID(String ID) {

this.ID= ID;

}

public String getName()

{

return Name;

}

public void setName(String Name) {

this.Name = Name;

}

}

 

package Pack;

import MyPack.*;

import java.util.Scanner;

public class Employee {

 

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.print("Enter the ID : ");

String id = s.nextLine();

System.out.print("Enter the Name : ");

String name = s.nextLine();

person p= new person();

p.varify(id, name);

System.out.println("\nThe name is : "+p.getName());

System.out.println("The ID is : "+p.getID());

}

}


In reply to First post

Re: Java Package Problem [Click Here]

by Fahim Shahriar (201-15-3629) -
package MyPack;

public class person {
private String ID = "201-15-3629";
private String name = "Fahim Shahriar";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person MyObj = new person();
System.out.println("Name: " + MyObj.name);
System.out.println("ID: " + MyObj.ID);
}
}

The "Pack" package can't call them(MyPack.person). Because the properties of the person in the "MyPack" Package are in a private firm which is why we cannot call it in the "Pack" package, but if we make the personal properties public then we can call it on the "Pack" package.
so, private properties can be called in their own package.
In reply to First post

Re: Java Package Problem [Click Here]

by Dipa Mondal Tumpa (201-15-3214) -
package MyPack;

public class person {
private String ID;
private String Name;
public void varify(String ID, String Name) {
this.ID = ID;
this.Name = Name;
}
public String getID()
{
return ID;
}
public void setID(String ID) {
this.ID= ID;
}
public String getName()
{
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
}

package Pack;
import MyPack.*;
import java.util.Scanner;
public class Employee {

public static void main(String[] args) {
Scanner d = new Scanner(System.in);
System.out.print("Enter the ID : ");
String id = d.nextLine();
System.out.print("Enter the Name : ");
String name = d.nextLine();
person j= new person();
j.varify(id, name);
System.out.println("\nThe name is : "+j.getName());
System.out.println("The ID is : "+j.getID());
}
}

Using the getter and setter method, it is possible to call the private values of MyPack from the pack package.
In reply to First post

Re: Java Package Problem [Click Here]

by Md. Uzzal Hossain Hridoy (201-15-3078) -

package MyPack;

public class person

{

private String ID = "201-15-3078";
private String Name = "Md. Uzzal Hossain Hridoy";

}
package Pack;
import MyPack.*;

public class employee

{

public static void main(String[] args)

{

person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);

}
}

In reply to First post

Re: Java Package Problem [Click Here]

by Tahmid chowdhury ID-(201-15-3064) -
package MyPack;
public class person {
private String ID = "201-15-3064";
private String name = "Md. Tahmid Chowdhury";
}
package Pack;
import MyPack.*;
public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

Some details:
Here we can see ‘Pack’ package can't call them (MyPack.person). So, reason is the properties of the person in "My Pack" which is a Package are in private form and that’s why we cannot call it in the ‘Pack’ package, but if we make the private assets public then we can call it "Pack" package.

ID-201-15-3064
In reply to First post

Re: Java Package Problem [Click Here]

by SOHANUR RAHMAN SOHAG_201-15-3161 -
package MyPack;
public class person {
private String ID = "201-15-3161";
private String name = "SOHANUR RAHMAN SOHAG";
}
package Pack;
import MyPack.*;
public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

DETAILS ABOUT THIS PROGRAMME:
In the above programme, we can see ‘Pack’ package can't call them (MyPack.person). So, the reason is the properties of the person in "My Pack" which is a Package is in private form and that’s why we cannot call it in the ‘Pack’ package, but if we make the private assets public then we can call it "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by B.M.Samiul Haque Real (201-15-3057) -
package MyPack;

public class person {
private String ID = "201-15-3057";
private String name = "B.M.Samiul Haque Real";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

As the "myPack" package is in a private form That's why we can't call it in another package like the "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by Abdullah Fahim(201-15-3201) -
package MyPack;

public class person {
private String ID = "201-15-3201";
private String name = "Abdullah Al Fahim";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

So, "Pack" package can't call them(MyPack.person). Because the properties of the person in "MyPack" Package are in private form which is why we cannot call it in the "Pack" package, but if we make the personal properties public then we can call it on "Pack" package.
We can't call it another package, mainly because the properties are private. However, private properties can be called in their own package
In reply to First post

Re: Java Package Problem [Click Here]

by Tanjil Alom (201-15-3079) -
package MyPack;
public class person {
private String ID = "201-15-3079";
private String name = "Tanjil Alom";
}
package Pack;
import MyPack.*;
public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

Details:
Here we can see ‘Pack’ package can't call them (MyPack.person). So, reason is the properties of the person in "My Pack" which is a Package are in private form and that’s why we cannot call it in the ‘Pack’ package, but if we make the private assets public then we can call it "Pack" package.
In reply to First post

Re: Java Package Problem [Click Here]

by Utsha Roy (201-15-3094) -
package MyPack;

public class person
{
private String ID = "201-15-3094";
private String Name = "Utsha Roy";
}
package Pack;
import MyPack.*;

public class employee
{
public static void main(String[] args)
{
person obj = new person();
System.out.println("Name: " + obj.Name);
System.out.println("ID: " + obj.ID);
}
}
In reply to First post

Re: Java Package Problem [Click Here]

by Md. Nazmus Sakib (201-15-3419) -
package MyPack;

public class person {
private String ID = "201-15-3292";
private String name = "MD. Alif Sheakh";

}
package Pack;
import MyPack.*;

public class Employee {
public static void main(String[] args) {
person myObj = new person();
System.out.println("Name: " + myObj.name);
System.out.println("ID: " + myObj.ID);
}
}

Here, "Pack" package can't call them(MyPack.person). Because the properties of the person in "MyPack" Package are in private form which is why we cannot call it in the "Pack" package, but if we make the personal properties public then we can call it on "Pack" package.
We can't call it another package, mainly because the properties are private. However, private properties can be called in their own package