Classroom examples
Classandobjecttest.java
Results
Hellow.java source program and results
There's nothing special about the output.
Initializeblockdemo.java source program and results
Mypackageclass.java source program and results
Objectequals.java source program and results
Strangeintegerbehavior.java source program and results
Test1.java source program and results
String Reverse output
Test2.java source program and results
Reverse output of the calling function
Test3.java source program and results
In the same package, the reverse output is called.
Class Root
{
static{
SYSTEM.OUT.PRINTLN ("Static initialization block of Root");
}
{
System.out.println ("Root's normal initialization block");
}
Public Root ()
{
SYSTEM.OUT.PRINTLN ("Root parameter-free constructor");
}
}
Class Mid extends Root
{
static{
SYSTEM.OUT.PRINTLN ("Static initialization block of mid");
}
{
SYSTEM.OUT.PRINTLN ("Normal initialization block for mid");
}
Public Mid ()
{
SYSTEM.OUT.PRINTLN ("Non-parametric constructor for mid");
}
Public Mid (String msg)
{
Calling overloaded constructors in the same class through this
This ();
System.out.println ("Mid with parametric constructor, its parameter value:" + msg);
}
}
Class Leaf extends Mid
{
static{
SYSTEM.OUT.PRINTLN ("Static initialization block of the Leaf");
}
{
SYSTEM.OUT.PRINTLN ("ordinary initialization block of the Leaf");
}
Public Leaf ()
{
A constructor that invokes a string argument in the parent class through Super
Super ("Java Initialization sequence demo");
System.out.println ("The constructor that executes the leaf");
}
}
public class Teststaticinitializeblock
{
public static void Main (string[] args)
{
New Leaf ();
}
}
Results
Static initialization block of root
Static initialization block for mid
Static initialization block of the leaf
Common initialization block for root
The parameterless constructor of root
Normal initialization block for mid
Parameter-free constructors for mid
The parametric constructor for mid, with parameter values: Java Initialization sequence Demo
Ordinary initialization blocks of the leaf
The constructor that executes the leaf
2015.10.13 Classroom