Exercise 3: (1) Create a class with a default constructor (that is, a parameterless constructor) to print a message in the constructor. Create an object for this class. P116
public class Test{public Test () {System.out.println ("Hello Word");} public static void Main (string[] args) {new Test ();} /** * Run result Hello Word */}
Exercise 4: (1) Add an overloaded constructor to the class in the previous exercise so that it accepts a character parameter and prints your own information and accepted parameters in the constructor.
public class Test{public Test (String msg) {System.out.println ("Hello" +msg);} public static void Main (string[] args) {new Test (' China ');} /** * Run result Hello China */}
Exercise 5: (2) Create a class named Dog that has an overloaded bark () method. This method should be overloaded according to the different basic data types and, depending on the version being called, print out different types of barking (barking), growl (howling), and write main () to invoke all the different versions of the method.
Java Programming Ideas Fourth Edition * Fifth chapter personal Practice