积少成多
2016-03-05 19:05
351 查看
---------------------------------------------------
public static void main(String[] args) {
try {
System.out.println(1);
problem();
} catch (RuntimeException e) {
System.out.println(2);
}catch (Exception e) {
System.out.println(3);
}finally{
System.out.println(4);
}
System.out.println(5);
}
private static void problem() throws Exception {
throw new Exception();
}
----------------输出1345---------------------------------
方法重载(Overloading)和方法重写(Overriding)都是多态性的表现
(1)方法重载是一个类中定义了多个方法名相同,而他们的参数的数量不同或数量相同而类型和次序不同,则称为方法的重载(Overloading)
(2)方法重写是在子类存在方法与父类的方法的名字相同,而且参数的个数与类型一样,返回
值也一样的方法,就称为重写(Overriding)
(3)方法重载是一个类的多态性表现,而方法重写是子类与父类的一种多态性表现.
------------------------------------------------------------------------
public class test01 {
public static void main(String[] args) {
A anA = new B();
anA.print();
}
}
class B extends A {
public B() {
}
public void print() {
System.out.println('B');
}
}
class A {
private int a;
public A() {
}
public A(int a) {
this.a = a;
}
public void print() {
System.out.println('A');
}
}
-----------------------输出B-------------------
wait()、notify()、notifyAll()是三个定义在Object类里的方法,可以用来控制线程的状态。
-----------------------------------------------------
StringBuffer stringBuffer = new StringBuffer("12345678901234567890123456");
int c = stringBuffer.capacity();
System.out.println(stringBuffer.length());//26
System.out.println(c); //42
public StringBuffer(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}
2)new StringBuffer();
答:16。
------------------------------------------------------
public static void main(String[] args) {
try {
System.out.println(1);
problem();
} catch (RuntimeException e) {
System.out.println(2);
}catch (Exception e) {
System.out.println(3);
}finally{
System.out.println(4);
}
System.out.println(5);
}
private static void problem() throws Exception {
throw new Exception();
}
----------------输出1345---------------------------------
方法重载(Overloading)和方法重写(Overriding)都是多态性的表现
(1)方法重载是一个类中定义了多个方法名相同,而他们的参数的数量不同或数量相同而类型和次序不同,则称为方法的重载(Overloading)
(2)方法重写是在子类存在方法与父类的方法的名字相同,而且参数的个数与类型一样,返回
值也一样的方法,就称为重写(Overriding)
(3)方法重载是一个类的多态性表现,而方法重写是子类与父类的一种多态性表现.
------------------------------------------------------------------------
public class test01 {
public static void main(String[] args) {
A anA = new B();
anA.print();
}
}
class B extends A {
public B() {
}
public void print() {
System.out.println('B');
}
}
class A {
private int a;
public A() {
}
public A(int a) {
this.a = a;
}
public void print() {
System.out.println('A');
}
}
-----------------------输出B-------------------
wait()、notify()、notifyAll()是三个定义在Object类里的方法,可以用来控制线程的状态。
-----------------------------------------------------
StringBuffer stringBuffer = new StringBuffer("12345678901234567890123456");
int c = stringBuffer.capacity();
System.out.println(stringBuffer.length());//26
System.out.println(c); //42
public StringBuffer(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}
2)new StringBuffer();
答:16。
------------------------------------------------------
相关文章推荐
- document.documentElement和document.body
- 公众平台测试帐号开发全流程第1篇-引言
- 第二节 操作系统是如何工作的
- js闭包(三)
- js闭包(二)
- Amicable numbers
- php实现一个单链表
- poj 3061 Subsequence (尺取法)
- 理解Android之ThreadLocal
- spring mvc 中controller是非线程安全的
- hdu 1166 敌兵布阵 (线段树、树状数组模板,单点更新)
- Spring框架学习(四)
- Android:Paint的setMaskFilter(MaskFilter maskfilter)
- TOEFL(20151220)分析
- C头文件
- 视频监控/存储系统设计要点
- 软件过程与项目管理(第一周作业)
- OpenCV2411 数据类型
- iOS URLencode加号变空格
- python 调用 shell 命令方法