Constructor Example in Java


Here is the simple program for printing basic example using Constructor in Java.

Source Code

import java.io.*;
import java.util.Scanner;
//www.tutorjoes.com
class constuct
{
  public static void main(String args[])
  {
   cons o =new cons(25);
   cons o1 =new cons();
   o.display();
   o1.display();
  }
}
class cons
{
  private int a;
  cons(int x)
  {
    a=x;
  }
  cons()
  {
    a=85;
  }
  public void display()
  {
   System.out.print("\nThe Value Of A is : "+a);
  }
}
To download raw file Click Here

Output

The Value Of A is : 25
The Value Of A is : 85


Learn All in Tamil © Designed & Developed By Tutor Joes