The code is incomplete at the moment, but I was wondering if I could use the String partNo the one that the constructor is making inside the mutator.
public static class Invoice{
Scanner sam = new Scanner(System.in);
int Quality;
double price;
public Invoice(){
}
public Invoice(String partNo, String description) {
}
public void setPartNo() {
System.out.println("Enter part no: ");
String partNo = sam.nextLine();
}
public static String getPartNo() {
return Invoice.getPartNo();
}
}
public static void main(String[] args) {
Invoice.getPartNo();
You here have a few parameters to your constructor, you don't do anything with, which is pretty pointless. They won't exist anymore once the constructor has finished executing, so it's impossible for your mutators to get them
Those parameters, set them up as instance members, that way your mutators will also have access to them.
Now, the same code with some improvements:
this, you will be able to use as follows:
If you are wondering whether your getter should be static: it should only be static if the field is static itself. Since you set the value by a parameter you pass to the constructor, it is doubtfull it should be static.
A parameter to the constructor should (usually) only set the value for that particular instance. If it's a static field, it will be set for every single instance of that type.