Initializing
by , 02-01-2012 at 06:23 PM (492 Views)
Output: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; } }
You are in Static block!
WaterSource constructor!
You are in initi block!
You are in SprinklerSystem constructor!
valve1 = Valve1
source = Constructed
Valve Strength = 0










Email Blog Entry
PDF to TIFF Conversion & Control...
Yesterday, 11:39 AM in Java Software