Java 习题 (55)

题目:
创建一个带有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);
    }
}

结果如下:
在这里插入图片描述
如果觉得不错,就用点赞或者关注或者留言,来代替五星好评~
谢谢~

猜你喜欢

转载自blog.csdn.net/BSCHN123/article/details/107725211
55