/*
Date : 11 November 2013
Author : Shivam Tiwari
Organization : http://mycodedock.blogspot.in/
Description : Demonstrating constructors in Java
*/
//Making the class
class UselessClass{
//declaring variables
int x;
double y;
//declring first constructor
//it can be used to set the value of variables while creating objects
UselessClass(int a, double b){
x = a;
y = b;
}
//declaring second constructor
//it can be used to create objects with zero values set in variables
UselessClass(){
x = 0;
y = 0;
}
}
public class Main
{
{
//creating an object using first constructor
UselessClass obj1 = new UselessClass(2,4.567);
//creating an objecct using second constructor
UselessClass obj2 = new UselessClass();
//Lets check by printing values
System.
out.
println("Printing from object that was created using first constructor"); System.
out.
println("int x = " + obj1.
x); System.
out.
println("double y = " + obj1.
y);
System.
out.
println("Printing from object that was created using second constructor"); System.
out.
println("int x = " + obj2.
x); System.
out.
println("double y = " + obj2.
y); }
}