A Cat Class with a Constructor - Java Object Oriented Design

Java examples for Object Oriented Design:Constructor

Description

A Cat Class with a Constructor

Demo Code

public class Main {
  public static void main(String[] args) {
    // Create a Cat object and ignore its reference
    new Cat();/* w w w. j  a v a 2s .  c o m*/
  
    // Create another Cat object and store its reference in c
    Cat c = new Cat();
  }
}
class Cat {
  public Cat() {
    System.out.println("Meow...");
  }
}

Result


Related Tutorials