thinking in java test5.8练习(16)(17)(18)
来源:互联网 发布:藏文软件下载 编辑:程序博客网 时间:2024/05/20 13:39
练习(16):创建一个String对象数据,并为每一个元素都复制一个String。用for循环来打印该数组。
public static void main(String[] args){ String[] str = new String[5]; str[0] = "杭州"; str[1] = "举办"; str[2] = "G20"; str[3] = "峰会"; str[4] = "!!!"; for (String s : str) { System.out.print(s); } }
练习(17):创建一个类,它有一个接受一个String参数的构造器,在构造阶段,打印该参数。创建一个该类的对象引用数组,但是不实际去创建对象赋值给该数组。当运行程序时,请注意来自对该构造器的调用中的初始化消息是否打印了出来。
这个看完题目就知道不会打印,对象都没有创建肯定不会调用构造函数。
public class test5_8_17 { public static void main(String[] args){ test17[] test17s = new test17[5]; }}class test17{ public test17(String str){ System.out.println(str); }}
练习(18):通过创建对象赋值给引用数组,从而完成前一个练习。
public class test5_8_17 { public static void main(String[] args){ test17[] test17s = new test17[5]; test17s[0] = new test17("0"); test17s[1] = new test17("1"); test17s[2] = new test17("2"); test17s[3] = new test17("3"); test17s[4] = new test17("4"); }}class test17{ public test17(String str){ System.out.println(str); }}
0 0
- thinking in java test5.8练习(16)(17)(18)
- thinking in java test5.1练习(1)(2)
- thinking in java test5.3练习(3)(4)(5)(6)(7)
- thinking in java test3.17练习(14)
- thingking in java test5.9练习(19)(20)(21)(22)
- thinking in java test5.5练习(10)(11)(12)finalize()方法
- thinking in java test4.5练习(6)(7)
- thinking in java test练习(13)(14)
- thinking in java test4.8练习(8)(9)(10)吸血鬼数字
- thinking in java test练习(8)(9)this关键字
- Thinking in Java(四)
- thinking in java test2.11练习(9)之java装箱拆箱
- Thinking In Java(java编程思想)
- java -- 性能(from thinking in java)
- java操作符(Thinking in Java)
- thinking in java test3.11练习(11)(12)(13)
- thinking in java test练习(12)(13)javadoc的生成
- thinking in java test3.4练习(2)(3)别名机制
- [jenkins工具]之二:jenkins的安装配置
- ios仿淘宝商品详情页面粘贴商品规格弹出模板
- LeetCode 112 Path Sum (DFS)
- 最大子序列和的四种算法
- linux下终端常用命令和vi命令修改文件及保存的使用方法
- thinking in java test5.8练习(16)(17)(18)
- 文章标题
- String的常用pre-defined methods
- 欢迎使用CSDN-markdown编辑器
- 使用php的curl函数post返回值为301永久迁移的问题。(Moved Permanently)
- 一周的外场测试
- Tomcat7 新的数据库连接池Tomcat jdbc pool介绍和配置
- Transaction not successfully started
- 在Xcode中使用Git进行源码版本控制(一)