+ 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(); } }

21st Mar 2017, 1:44 PM
Stefan
Stefan - avatar
5 Answers
+ 7
Creating an object of class Animal and calling the class method bark().
21st Mar 2017, 1:45 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 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.
21st Mar 2017, 2:01 PM
Meharban Singh
Meharban Singh - avatar
+ 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)
6th May 2017, 2:55 PM
James T Togara
James T Togara - avatar
0
Thank you guys!
31st Jan 2019, 10:26 AM
Stefan
Stefan - avatar