关于java:java中赋值问题

41次阅读

共计 920 个字符,预计需要花费 3 分钟才能阅读完成。

public class ReferenceTest {

static class Student{
    public Bag b;
    public int a;
    public String s;
    public String getS() {return s;}
    public void setS(String s) {this.s = s;}
    public int getA() {return a;}
    public void setA(int a) {this.a = a;}
    public Bag getB() {return b;}
    public void setB(Bag b) {this.b = b;}
}

static class Bag{

    public String name;
    public String getName() {return name;}
    public void setName(String name) {this.name = name;}
}
public static void main(String[] args) {// 援用 

// Student student = new Student();
// Bag bag1= student.b;
// System.out.println(bag1);
// student.b = new Bag();
// System.out.println(bag1);
// 8 种根本变量
// Student student = new Student();
// int a= student.a;
// System.out.println(a);
// student.a = 1;
// System.out.println(a);
// 字符串
// Student student = new Student();
// String s= student.s;
// System.out.println(s);
// student.s = “s”;
// System.out.println(s);
//// int a=0;
// int b =a;
// System.out.println(b);
// a=1;
// System.out.println(b);
String s = “s”;

    String s1 = s;
    System.out.println(s1);
    s="s2";
    System.out.println(s1);
}

}

正文完
 0