0

What will be difference between the bark method with static keyword and without static keyword

public class Animal { void bark() { System.out.println("Woof-Woof"); } } class MyClass { public static void main(String[ ] args) { Animal dog = new Animal(); dog.bark(); } }

23rd Sep 2017, 3:43 PM
Sourabh jain
Sourabh jain - avatar
1 Resposta
+ 4
public class Animal { static void bark() { System.out.println("Woof-Woof"); } } class MyClass { public static void main(String[ ] args) { Animal.bark(); } } you can call the bark() method directly by using the classname, without creating an object for it
23rd Sep 2017, 3:57 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar