顯示具有 Object 標籤的文章。 顯示所有文章
顯示具有 Object 標籤的文章。 顯示所有文章

C 語言 物件Object

一個物件把相關的資料和操作包裝起來
以堆疊stack來說明物件

18.2.1堆疊結構

第一個物件元素 - 結構
struct stack{
int top;
char elements[100];
};
typedef struct stack Stack;


18.2.2 堆疊函式宣告

第二個物件元素 - 函式
void init_stack(Stack *s)
int stack_empty(Stack *s)
int stack_full(Stack *s)
void push_stack(Stack *s, char c)
int pop_stack(Stack *s);


標頭檔<xxx.h> 與 "xxx.h"的差異
以<>標示者,編譯器會到系統標頭檔目錄尋找
以""標示者,編譯會到引入""的程式的目錄尋找

18,2.3 堆疊函式實作

Object Class

Class Overview


The root class of the Java class hierarchy. All non-primitive types (including arrays) inherit either directly or indirectly from this class.

Public Constructors
Object()
Constructs a new instance of Object.

能改寫的Public Methods 有equals(Object o),hashCode(),toString()。其中equals和hashCode要同時改寫。
Public Methods
booleanequals(Object o)
Compares this instance with the specified object and indicates if they are equal.
final Class<?>getClass()
Returns the unique instance of Class that represents this object's class.
inthashCode()
Returns an integer hash code for this object.
final voidnotify()
Causes a thread which is waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.
final voidnotifyAll()
Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.
StringtoString()
Returns a string containing a concise, human-readable description of this object.
final voidwait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
final voidwait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.
final voidwait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Protected Methods
Object    clone()
Creates and returns a copy of this Object.
void    finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.