[問題] java與C++ 關於inner class載入記憶體之時間點
在一個class object產生出來前 編譯器會先將這個.class載入到記憶體
那我現在class裡面包著一個class
降子是分出兩個.class
對吧
interface Destination{ String readLabel(); }
public class Parcel4{
public Destination dest( String s ){
class PDestination implements Destination{
private String label;
private PDestination( String whereTo ){
label = whereTo;
}
public String readLabel(){ return label; }
}
return new PDestination( s );
}
public static void main( String[] args ){
Parcel4 p = new Parcel4(); //倒數第4行
Destination d = p.dest("Tanzania"); //倒數第3行
}
}
像這樣的一個程式?
Q1: PDestination.class會在倒數第3還4行載入到記憶體?
換句話說,Parcel4.class和 PDestination.class是同時載入到記憶體,
還是有先後差別
那麼現在如果換成C/C++
class Destination{
public:
virtual void readLabel(void) = 0;
};
class Parcel4{
public:
Destination* dest( string s ){
class PDestination: public Destination{
public:
PDestination( string whereTo ){
label = whereTo;
}
private:
string label;
void readLabel(void){
cout<<label<<endl;
}
};
return new PDestination(s);
}
};
int main(){
Parcel4 p;
Destination* d = p.dest("Test");
(*d).readLabel();
system("pause");
return 0;
}
Q2: 同樣的問題轉成C++變成有點不會問了@@
編譯過後的outer,inner class同時載進去記憶體? 還是會有先後之分?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.250.224.67