stack::~stack(){}
複製建構式
stack::stack(const stack& old_stack);
##ReadMore##
範例:
stack a_stack;
a_stack.push(2);
stack b_stack(a_stack); //複製a-stack資料給b_stack
工作忙了,事情多了,越發越少,備忘錄就到這個段落吧!
stack::~stack(){}
stack::stack(const stack& old_stack);
stack a_stack;
a_stack.push(2);
stack b_stack(a_stack); //複製a-stack資料給b_stack
/*可使用兩種方式來建構*/
class ex1
{
ex1(int size);
}
ex1 init1(10);
ex1 init2 = 10;
/*只可使用一種方式來建構*/
class ex2
{
explicit ex2(int size);
}
ex2 init1(10);
##ShowAll##
class MyOuter {
private int x = 7;
static private int sx = 9;
static class MyStatic {
private int x = 77;
static private int sx = 99;
public void fooA() { // non-static member
System.out.println("static inner class A.");
System.out.println(sx); //
System.out.println(MyOuter.sx); //
System.out.println(x); //
System.out.println(this.x); //
//static inner class中沒有MyOuter的this指標
//System.out.println(MyOuter.this.x);
}
public static void fooB() { // static member
System.out.println("static inner class B.");
System.out.println(sx);
System.out.println(MyOuter.sx);
}
}
}
public class StaticInnerClass {
public static void main(String[] args) {
//MyOuter.MyStatic.fooB();
MyOuter.MyStatic s = new MyOuter.MyStatic();
s.fooA();
s.fooB();
}
interface Pet {
void skill();
void move();
}
public class AnonymousClass {
public static void main(String[] args) {
Pet p = new Pet()
{
public void skill(){
System.out.println("我會握手 !");
}
public void move(){
System.out.println("我會跑步 !");
};
};
p.skill();
p.move();
}
}
abstract class Car {
public void power(){}
abstract void move();
}
public class Tank extends Car{
public void move(){
Syatem.out.println("Track");
}
}
public class Test {
void a() {
b(); //正確
d(); //正確
}
void b() {}
static void c() {
b(); //錯誤,不可直接呼叫b()
d(); //正確,可直接呼叫d()
}
static void d(){
new Test().b(); //正確,可直接呼叫b()
}
}
精神
1.抽象化(Abstraction)
2.繼承(Inheritance)
特徵
1.繼承(Inheritance)
2.封裝(Encapsulation)
3.多型(Polymorphism)