本篇文章為大家展示了java中對象調(diào)用成員變量與成員實(shí)例方法是什么,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
使用對象訪問類中的成員:
對象名.成員變量;
對象名.成員方法();
成員變量的默認(rèn)值:
具體實(shí)例代碼:
public class StudentTest_01 { public static void main(String[] args) { //創(chuàng)建對象格式,類名 對象名 = new 類名(); //無參數(shù)使用方法 Student s2 = new Student(); s2.setName("千尋1"); s2.setAge(25); System.out.println("姓名:"+ s2.getName()); System.out.println("年齡:"+ s2.getAge()); System.out.println("‐‐‐‐‐‐‐‐‐‐"); //有參數(shù)使用方法 Student s = new Student("千尋2",23); System.out.println("姓名:"+ s.getName()); //null System.out.println("年齡:"+ s.getAge()); //0 System.out.println("‐‐‐‐‐‐‐‐‐‐"); //調(diào)用成員方法 s.study(); s.eat(); }}
上述內(nèi)容就是java中對象調(diào)用成員變量與成員實(shí)例方法是什么,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。