Still learning OOP. Meanwhile I got the feeling that some points are getting clearer, but sometimes -like in the following program, I don't understand, what the problem is:
If I try to compile this I get:
Computer.java:11: error: illegal start of type System.out.println("Hello");
If I remove the System.out.println then it works. So my question is: Why is a println at this position impossible? Using println in methods is ok, but not when defining classes?
Perhaps you can answer me another question too. When i run this program, there is a new notebook object created (by the main class in an other file). Then the methods sell and buy are used "on top" of this object, telling the user "Now you got ... items". Is it possible to get the Name of the object in this println. For example: If it is a notebook Object: Now you got xxx Notebooks, If it is an PC Object: Now you got xxx PCs..."
System.out.println(...); is a statement.
You are not allowed statements at the “top level” in your class; you ought to put it inside a method or constructor (or an initaliser, but I am not fond of initialiser). Unless you need it for debugging, you ought not to put println statements in constructors.