Java 使用构造方法创建对象

This commit is contained in:
YuCheng Hu 2018-11-21 15:04:47 -05:00
parent 63473ed3e1
commit cab35e0dd2
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package com.ossez.lang.tutorial.objplusclass;
/**
*
* @author YuCheng
*
*/
public class CreateObject {
public CreateObject(String name) {
// This constructor has one parameter, name
System.out.println("小狗的名字是: " + name);
}
public static void main(String[] args) {
// Following statement would create an object myPuppy
CreateObject myPuppy = new CreateObject("Tomcat");
}
}