Why does it not execute?


#1

class Dog {

int age;

public Dog(int dogsAge) {
age = dogsAge;

}
public void bark(){
System.out.println ("Woof");
}

public static void main(String[] args) {

Dog spike = new Dog(5);

}

}
//It compiles fine. But no output why?


#2

HI if you want to print "Woof" you should add

spike.bark();

in the main function.


#3

functions inside objects are called methods. Just like normal function, you need to call a method before it is executed