Is it possible to asign a value to a var while i a subclass when the data field comes from it's super class?
I want to use it in another subclass to my super class.
I want to use it in another subclass to my super class.
public class Vm{
protected String name;
protected int price;
}
public class Select extends Vm{
public void event(){
super.name ="Myname";
super.price=10;
}
}
public class Payment extends Vm{
public void printOut(){
System.out.println(name+": "+price);
}
}
public class Main {
public static void main(String[] args) {
Select a = new Select();
a.event();
Payment b = new Payment();
b.printOut();
}
}
public class Vm{
protected String name;
protected int price;
}
public class Select extends Vm{
public void event(){
super.name ="Myname";
super.price=10;
}
}
public class Payment extends Vm{
public void printOut(){
System.out.println(name+": "+price);
}
}
public class Main {
public static void main(String[] args) {
Select a = new Select();
a.event();
Payment b = new Payment();
b.printOut();
}
}
Comment