Java Ch7:理解static, final与abstract修饰符的实战练习

需积分: 50 2 下载量 47 浏览量 更新于2024-09-03 收藏 121KB PDF 举报
"本资源是一份关于Java编程语言中的三个关键修饰符——static、final和abstract的练习题。这些题目涵盖了静态属性、静态成员方法、非静态属性以及静态初始化代码块的概念和用法。 1. 静态属性(练习1):在提供的代码中,`static int a;`定义了一个类级别的变量a,属于所有类实例共享。在`main`方法中,对两个`MyClass`对象`mc1`和`mc2`分别赋值,然后打印。由于静态变量不依赖于特定的对象实例,因此输出结果将是: - mc1.a: 100 - mc1.b: 200 - mc2.a: 300 - mc2.b: 400 2. 静态成员与非静态成员(练习2):本题要求识别哪些行会编译出错。静态成员`a`和`b`可以被类的任何静态方法访问,所以//1, //5, //6不会有错误。但是,非静态方法`fa()`和`fb()`不能直接访问静态成员`a`,因此//3和//7会报错。因为`fa()`和`fb()`是静态方法,它们可以在`m1`和`m2`中调用静态成员`b`,所以//2, //4, //6, //8都不会报错。正确答案是C和G。 3. 静态计数器(练习3):`static int count = 0;`定义了一个类级别的计数器,在每个`MyClass`对象创建时都会自增并打印。由于`count`只有一份,三个`MyClass`对象创建后,输出将是: - MyClass mc1: 1 - MyClass mc2: 2 - MyClass mc3: 3 4. 静态初始化代码块(练习4):`static int i = 10;`表示一个静态初始化代码块,它会在类加载时执行且仅执行一次。因此,即使有多个`MyClass`实例,`i`的值始终为10。这部分的输出不会在`main`方法中显示,因为它是在类级别初始化的。 总结来说,这些练习着重考察了Java中静态(static)和非静态(non-static)成员的理解,以及静态初始化块的执行顺序。通过解决这些问题,学习者将加深对Java基础概念如作用域、生命周期和内存管理的理解。"
2020-02-08 上传
实验报告包含详细的实验截图和命令 Task 1: Configure Local AAA Authentication for Console Access on R1 Step 1. Test connectivity. · Ping from PC-A to PC-B. · Ping from PC-A to PC-C. · Ping from PC-B to PC-C. Step 2. Configure a local username on R1. Configure a username of Admin1 and secret password of admin1pa55. Step 3. Configure local AAA authentication for console access on R1. nable AAA on R1 and configure AAA authentication for console login to use the local database. Step 4. Configure the line console to use the defined AAA authentication method. Enable AAA on R1 and configure AAA authentication for console login to use the default method list. Step 5. Verify the AAA authentication method. Verify the user EXEC login using the local database. Task 2: Configure Local AAA Authentication for VTY Lines on R1 Step 1. Configure a named list AAA authentication method for VTY lines on R1. Configure a named list called TELNET-LOGIN to authenticate logins using local AAA. Step 2. Configure the VTY lines to use the defined AAA authentication method. Configure the VTY lines to use the named AAA method. Step 3. Verify the AAA authentication method. Verify the Telnet configuration. From the command prompt of PC-A, Telnet to R1. Task 3: Configure Server-Based AAA Authentication Using TACACS+ on R2 Step 1. Configure a backup local database entry called Admin. For backup purposes, configure a local username of Admin and secret password of adminpa55. Step 2. Verify the TACACS+ Server configuration. Select the TACACS+ Server. From the Config tab, click on AAA and notice that there is a Network configuration entry for R2 and a User Setup entry for Admin2. Step 3. Configure the TACACS+ server specifics on R2. Configure the AAA TACACS server IP address and secret key on R2. Step 4. Configure AAA login authentication for console access on R2. Enable AAA on R2 and configure all logins to authenticate using the AAA TACACS+ server and if not available, then use the local database. Step 5. Configure the line console to use the defined AAA authentication method. Configure AAA authentication for console login to use the default AAA authentication method. Step 6. Verify the AAA authentication method. Verify the user EXEC login using the AAA TACACS+ server. Task 4: Configure Server-Based AAA Authentication Using RADIUS on R3 Step 1. Configure a backup local database entry called Admin. For backup purposes, configure a local username of Admin and secret password of adminpa55. Step 2. Verify the RADIUS Server configuration. Select the RADIUS Server. From the Config tab, click on AAA and notice that there is a Network configuration entry for R3 and a User Setup entry for Admin3. Step 3. Configure the RADIUS server specifics on R3. Configure the AAA RADIUS server IP address and secret key on R3. Step 4. Configure AAA login authentication for console access on R3. Enable AAA on R3 and configure all logins to authenticate using the AAA RADIUS server and if not available, then use the local database. Step 5. Configure the line console to use the defined AAA authentication method. Configure AAA authentication for console login to use the default AAA authentication method. Step 6. Verify the AAA authentication method. Verify the user EXEC login using the AAA TACACS+ server. Step 7. Check results.
2022-04-12 上传