package com.lzw;public class Test45 {? ??? ??? ? public void print() { System.out.println("Hello World"); }? ??? ? public static void main(String[] args){? ? ? ??? ? ? ? //在 main 方法中調用 print 方法? ? ? ? HelloWorld test=new HelloWorld();? ? ? ? test.print();? ? }}
5 回答
已采納

紫帆梓
TA貢獻3條經驗 獲得超3個贊
要先定義HelloWorld這個類,而不是Test45:
public?class?HelloWorld?{ ????public?void?print()?{ ????????System.out.println("Hello?World"); ????} ????public?static?void?main(String[]?args){? ????????//在?main?方法中調用?print?方法 ????????HelloWorld?test=new?HelloWorld(); ????????test.print(); ????} }

waste_time
TA貢獻43條經驗 獲得超16個贊
public class Test45 {
? ??
? ??
? ? public static void print() {
System.out.println("Hello World");
}
? ??
? ? public static void main(String[] args){
? ? ? ??
? ? ? ? //在 main 方法中調用 print 方法
? ? ? ??print();
? ? }
}
添加回答
舉報
0/150
提交
取消