标签:Java
导读学习Java的过程中,一开始很容易被这些各种变量绕晕,这篇博客主要介绍了这几种变量之间的关系和区别。
package com.cunyu.demo
public class Demo {
private String name; //成员变量、实例变量
private int age; //成员变量、实例变量
private int ID; //成员变量、实例变量
public static final String school = "卡塞尔学院"; //成员变量、静态变量(类变量)
public static String level = "SSS"; //成员变量、静态变量(类变量)
public int getAge() {
return age;
}
public int getId() {
return ID;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public void setId(int ID) {
this.ID = ID;
}
public void setName(String name) {
this.name = name;
}
public void study(){
String subject1 = "屠龙"; //局部变量
String subject2 = "炼金术"; //局部变量
System.out.println("学习科目: " + subject1 + "、" + subject2);
}
public static void main(String[] args) {
Demo demo = new Demo();
demo.setAge(23);
demo.setId(14000001);
demo.setName("楚子航");
System.out.println("ID: " + demo.getId() + "Age: " + demo.getAge() + "Name: " + demo.getName());
System.out.print("主修科目: ");
demo.study();
System.out.println("学院:" + Demo.school);
System.out.println("等级:" + Demo.level);
}
}
标签:Java
原文地址:http://blog.51cto.com/13473568/2127973