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