package com.StaticDemo; public class Test2 { public static void main(String[] args) { //1.类方法的用法 //类名.类方法(推荐) Stndent1.printHelloWord(); //对象.类方法(不推荐) Stndent1 s = new Stndent1(); s.printHelloWord(); //2.实例方法的用法 //对象.实例方法 s.printPass(); // Stndent1.printPass();//报错 } }
package com.StaticDemo; public class Stndent1 { double score; //类方法:有Static修饰,属于类 public static void printHelloWord(){ System.out.println("Hello Word"); System.out.println("Hello Word"); } //实例方法(对象的方法) public void printPass(){ System.out.println("成绩"+ (score>=60 ? "及格":"不及格")); } }
标签:Stndent1,System,用法,printPass,printHelloWord,方法,public From: https://www.cnblogs.com/Karl-hut/p/17438238.html