帮忙写个Java小程序

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:35:08
用protected数据创建一个类。在相同的文件里创建第二个类,用一个方法操纵第一个类里的protected数据。

public class test {
public static void main(String[] args){
A a = new A();
System.out.println(a.num);
}
}

class A{
protected int num =1;
}

class Type1{
protected int i;
}

class Type2{
public void changeType1(Type1 t,int j){
t.i = j
}
}

是这个意思吗?