//The first one to move the brain Packagehands on the brain 3; Public classClassandobjecttest { Public Static voidMain (string[] args) {//create an instance of a class that defines an instance of an object variable referenceMyClass obj =NewMyClass (); //invoking the public method of a class through an object variableObj.mymethod ("Hello"); //Assigning a value to a propertyObj.setvalue (100); //the current value of the output propertySystem.out.println (Obj.getvalue ()); //direct access to object public fieldsObj.information = "Information"; //the current value of the Output object public fieldSystem.out.println (obj.information); }}/*** Examples of custom Java classes*/classMyClass {//Public Fields PublicString information = ""; //Customizing Public Java instance Methods Public voidMyMethod (String argu) {System.out.println (ARGU); } //Define properties: Private field +get method +set method Private intvalue; Public intGetValue () {returnvalue; } Public voidSetValue (intvalue) { This. Value =value; }} Run as follows://The second one , the brain. Packagehands on the brain 3;classroot{Static{System.out.println ("Static initialization block of root"); } {System.out.println ("Root's normal initialization block"); } PublicRoot () {System.out.println ("Root parameterless constructor"); }}classMidextendsroot{Static{System.out.println ("Static initialization block for mid"); } {System.out.println ("Normal initialization block for mid"); } PublicMid () {System.out.println ("No parametric constructor for mid"); } PublicMid (String msg) {//calling overloaded constructors in the same class through this This(); System.out.println ("Mid with parametric constructor, its parameter value:" +msg); }}classLeafextendsmid{Static{System.out.println ("Static initialization block of the leaf"); } {System.out.println ("Plain initialization block of the leaf"); } PublicLeaf () {//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 classteststaticinitializeblock{ Public Static voidMain (string[] args) {NewLeaf (); }} is as follows:
The third experiment and the hands-on brain