You can only access static members using the name of the type.
Therefore, you need to either write,
`MyClass.MyItem.Property1`
Or (this is probably what you need to do) make Property1
an instance property by removing the static
keyword from its definition.
Static properties are shared between all instances of their class, so that they only have one value. The way it's defined now, there is no point in making any instances of your MyItem class.
Static means that there is only one instance of "snack" in Hello, not one per each separate instance of the "Hello" class, or more-so, it means that there will be one commonly shared "snack" reference among all instances of the "Hello" class.
So if you were to do a "new Hello" anywhere in your code: A- in the first scenario (before the change, without using "static"), it would make a new clock every time a "new Hello" is called, but B- in the second scenario (after the change, using "static"), every "new Hello" instance would still share and use the initial and same "snack" reference first created.
Unless you needed "snack" somewhere outside of main, this would work just as well:
package hello;
public class Hello
{
public static void main(String args[])
{
Snack snack=new Snack();
snack.ticketCost();
}
}