+ 1
If someone could explain to me what is happening in this code? Let's just say I am stuck...
class MyClass { public static void main(String[ ] args) { Animal dog = new Animal(); dog.bark(); } }
5 Respostas
+ 7
Creating an object of class Animal and calling the class method bark().
+ 6
Line 1:- You created a class named MyClass
Line 2:- Thats a main method :--) . That's where your program starts after compilation.
Line 3:-You created an object named dog of the class Animal,by calling its constructor (Animal()) using new keyword.
Line 4:-You used your created object to call its method named bark.
+ 2
I might be to late to answer the question but this might also help you.
There are three things here : The object (Dog )
: Its class (Animal)
: Its Behavior ( Barking) shown by calling the
method bark()
The method created his way
static void bark(){
System.out.println(Hu-Hu)
0
Thank you guys!