Why does it not execute?

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?

HI if you want to print “Woof” you should add


in the main function.

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

1 Like