Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 3

Exercise 3: Create a class with a default constructor (one that takes no arguments) that prints a message. Create an object of this class.

class Kabayo
{
     Kabayo()
     {
        System.out.println("isa lang kabayo");
    }
}

public class DefaultConstructorTest
{
    public static void main(String[] args)
    {
        Kabayo k = new Kabayo();
    }
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *