View RSS Feed

fatabass

Initializing

Rating: 1 votes, 1.00 average.
by , 02-01-2012 at 06:23 PM (657 Views)
Java Code:
package myPackage;

public class SprinklerSystem 
{
	private String valve1;
	private int valveStrength;
	private WaterSource source = new WaterSource();
	
	static 
	{
		System.out.println("You are in Static block!");
	}

	{
		System.out.println("You are in initi block!");
		this.valve1 = "Valve1 ";
	}
	

	
	SprinklerSystem()
	{
		System.out.println("You are in SprinklerSystem constructor!");
	}

	public static void main(String[] args) 
	{
		SprinklerSystem mySystem = new SprinklerSystem();
		System.out.println(mySystem);
	}
	
	public String toString()
	{
		return "\n" + "valve1 = " + this.valve1 
				+ "\n" + "source = " + this.source + "\n"
				+ "Valve Strength =  " + this.valveStrength;
	}

}

class WaterSource
{
	private String s;
	
	WaterSource()
	{
		System.out.println("WaterSource constructor!");
		this.s = "Constructed";
	}
	
	public String toString()
	{
		return s;
	}
}
Output:


You are in Static block!
WaterSource constructor!
You are in initi block!
You are in SprinklerSystem constructor!

valve1 = Valve1
source = Constructed
Valve Strength = 0

Submit "Initializing" to Facebook Submit "Initializing" to Digg Submit "Initializing" to del.icio.us Submit "Initializing" to StumbleUpon Submit "Initializing" to Google

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments