compile error: string is private with powershell
-
a very beginner question... i'm a newbie in programming... just started java and read about packaging... i created i directory called firstproject and put a directory with one class inside of it and a FirstProject source file in the firstproject directory itself. i made a class in that package directory that has a private string in it and tried to invoke from FirstProject source file but getting compile error that the string is private... i tried changing the string into protected or even public but still getting this error... this is the class src file...
package stickers;
public class Sticker
{
private String note;Sticker(String note)
{
this.note = note;
}public void displayNote()
{
System.out.println(note);
}
}this is the FirstProject src file...
package firstproject;
import stickers.Sticker;
public class FirstProject
{
public static void main(String[] args)
{
Sticker sticker = new Sticker("hello sticky mehdi");
sticker.displayNote();
}
}this is the actuall error: error: Sticker(String) is not public in Sticker; cannot be accessed from outside package
-
a very beginner question... i'm a newbie in programming... just started java and read about packaging... i created i directory called firstproject and put a directory with one class inside of it and a FirstProject source file in the firstproject directory itself. i made a class in that package directory that has a private string in it and tried to invoke from FirstProject source file but getting compile error that the string is private... i tried changing the string into protected or even public but still getting this error... this is the class src file...
package stickers;
public class Sticker
{
private String note;Sticker(String note)
{
this.note = note;
}public void displayNote()
{
System.out.println(note);
}
}this is the FirstProject src file...
package firstproject;
import stickers.Sticker;
public class FirstProject
{
public static void main(String[] args)
{
Sticker sticker = new Sticker("hello sticky mehdi");
sticker.displayNote();
}
}this is the actuall error: error: Sticker(String) is not public in Sticker; cannot be accessed from outside package
You need to make your constructor public so other packages can access it:
public class Sticker
{
private String note;public Sticker(String note)
{
this.note = note;
}
// ... etcI would recommend going to The Java Tutorials[^] and working through them.