Pin It

Program to demonstrate how Constructor works in Java ?

A Simple Java program demonstrating how a Constructor works in Java :

package com.hubberspot.objects.example;

class IPL {
  IPL() {  // Constructor 
    System.out.println("This season's IPL teams are :");
    System.out.println("1. Deccan Chargers");
    System.out.println("2. Kolkata Night Riders");
    System.out.println("3. Mumbai Indians");
    System.out.println("4. Chennai Super Kings");
    System.out.println("5. Rajasthan Royals");
    System.out.println("6. Royal Challengers Bangalore");
    System.out.println("7. Kings XI Punjab");
    System.out.println("8. Pune Warriors India");
    System.out.println("9. Delhi Daredevils");

public class SimpleConstructor {
  public static void main(String[] args) {
    new IPL();

Output of the program :

Please Give Us Your 1 Minute In Sharing This Post!
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
© 2012 Learn Java by Examples Template by Hubber Spot