JavaSE,
分享于 点击 21362 次 点评:210
JavaSE,
面向对象三大特征:封装、继承、多态。封装:防止外部程序直接访问,有利于数据的完整性。
public class People {
private String name;
private String sex;
private int age;
生成get, set,方法
想要什么结果,可以在setXxx(),getXxx()方法中加入逻辑控制
抽象类语法
[访问控制符] abstract class 类名{
接口(interface). 接口中没有普通方法,接口中所有方法都是抽象方法。
[修饰符] interface 接口名{
eg
public interface A{
int a = 5;
void fun1();
}
所有的异常都是由五个关键字 try、catch、throw、throws 和 finally 来处理
try…catch 最基本的异常处理方式
try…catch…finally如果无论发生什么情况,有些代码必须执行,则可以放到finally块中
Final、finally、finalize的区别
Final修饰类:类不可被继承
Final修饰变量:变量值不可变
Final修饰方法:方法不可被重写
Finally用于捕获异常 try catch finally语句
Finalize用于处理垃圾回收
Iterator是对 collection(集合)进行迭代的迭代器。
Iterator接口(遍历集合)
ArrayList (List 接口的大小可变数组的实现)
使用迭代器步骤:
1.取得迭代器
2.while(it.hasNext())判断是否有下一个元素
3.while循环体中做操作eg:输出、删除….
eg:
publicclass Test1 {
publicstaticvoid main(String[] args) {
ArrayList al = new ArrayList();
al.add("A");
al.add("B");
al.add("C");
al.add("B");
//循环输出集合元素
System.out.println("循环输出集合元素如下:");
for(int i = 0;i<=al.size()-1;i++){
System.out.println(al.get(i));
}
//迭代器输出
System.out.println("迭代器输出集合元素如下:");
Iterator it = al.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
相关文章
- 暂无相关文章
用户点评