Java Programming Ideas Fourth Edition * Fifth chapter personal Practice

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.