+ 1
Why do this instead of this?
Why do this to call a class? tuna tunaObject = new tuna (); tunaObject.simpleMessage(); Instead of this? tuna.simpleMessage(); Also what does new mean and what is an instance?
2 Respuestas
+ 2
tuna is your class and tunaObject is an instance of this class. You can use though tuna.simpleMessage() ONLY IF you declare your class as static, where you dont have to create an object of this class to use it.
- 1
Your confusion is because stupid example.
Firstly: By convention, classes should start with capital letter. Tuna.
So imagine you have Tunas in the pond. For every Tuna in the pond, make a
new Tuna().
Pretty self-explanatory. Those individual tunas are called instances of class Tuna.
Now say your tunas can move. That's a method.
tuna1.move(North)
tuna2.move(South)
Tuna.move() doesn't make sense because the class of Tuna, i.e the species, doesn't move around.