题目:
创建一个带有protected数据的类。运用在第一个类中处理protected数据的方法在相同的文件中创建第二个类。
解答:
package six;
class one {
protected int i;
}
class two {
protected int j;
}
public class sixExercise {
public static void main(String[] args){
one One = new one();
One.i = 1;
System.out.println("This is the first class: " + One.i);
two Two = new two();
Two.j = 2;
System.out.println("This is the second class: " + Two.j);
}
}
结果如下:
如果觉得不错,就用点赞或者关注或者留言,来代替五星好评~
谢谢~