// 有参数的普通方法 创建了有返回值的方法
public String info(String fruit) {
// 返回一个字符串 String (文本类型)
return fruit + “汁”;
}
// 所有程序的入口处 主要的方法
public static void main(String[] args) {
//通过new 关键字 创建一个对象 = 赋值运算符 从右向左赋值
//通过StudentText 创建一个对象 其中的zhang就是对象名 .点操作符用来调用方法和属性
StudentText zhang = new StudentText();// 调用了无参构造函数
zhang.say();// 通过对象调用方法(普通的方法)
String info = zhang.info(“苹果”);// 通过对象调用方法(有返回值的方法)
System.out.println(“我喜欢” + info);
// 执行代码
System.out.println(“HELLO JAVA”);
StudentText cui=new StudentText();
cui.say();
StudentText.say();
say();
// main alt+/ ; syso alt+/
}// alt+/ 万能键
Java方法调用
最新推荐文章于 2022-11-18 19:31:42 发布
