Java 使用构造方法创建对象
This commit is contained in:
parent
63473ed3e1
commit
cab35e0dd2
@ -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");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user