1 / 10

public class Up extends Object { public static int w; public int x;

PRIMO ESERCIZIO (del 26-5-2004) Mostrare l'evoluzione dello stato (ambiente di classi, heap, pila, System.out) dopo ciascuna istruzione del main:. public class Up extends Object { public static int w; public int x; public void met1() {w=x+4; x=x+1;} {x=3;} }

Télécharger la présentation

public class Up extends Object { public static int w; public int x;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PRIMO ESERCIZIO (del 26-5-2004) Mostrare l'evoluzione dello stato (ambiente di classi, heap, pila, System.out) dopo ciascuna istruzione del main: public class Up extends Object { public static int w; public int x; public void met1() {w=x+4; x=x+1;} {x=3;} } public class Down extends Up { public Up y; public void met2() {y=new Down(); y.x=x+1; y.met1();} public void met1() {x=x+w; w=0;} {x=w;} } public class Princ extends Object { public static void main() { Up p1 = new Up(); p1.w = p1.x + 1; p1.met1(); Down p2 = new Down(); p2.met2(); } }

  2. Ambiente delle classi 0 Nome classe Classe ereditata static non static Princ Object Down Up m2 3 Up Object 1 2 m1 Object

  3. Ambiente delle classi 0 Descrmet1 = <-, {w=x+4; x=x+1; , Up> DescrUp = <-, {x=3;}, Up> Descrmet2 = <-, {y=new Down(); y.x=x+1; y.met1();}, Down> Descr'met1 = <-, {x=x+w; w=0;}, Down> DescrDown = <-, {x=3;x=w;}, Down>

  4. Princ Pila dei Frames vuota! Stato iniziale: <0 , s0 , x0 >

  5. Prima Istruzione del main: Up p1 = new Up(); < Up p1 = new Up();,0 , s0 , x0 > com < 0 , s1 , x1 > Princ Up p1 l1 l1 m1' x1 s1

  6. Seconda Istruzione del main: p1.w = p1.x + 1; < p1.w = p1.x+1; , 0 , s1 , x1 > com < 1 , s1 , x1 > Modifica solo l'ambiente delle classi. Frame delle variabili statiche di UP: 1 1'

  7. Terza Istruzione del main: p1.met1(); < p1.met1(); , 1 , s1 , x1 > com < 2 , s1 , x2 > Modifica l'ambiente delle classi e l'heap. m1'(met1) = < -, {w=x+4; x=x+1}, l1 > Up 1' 1'' l1 m1' x2

  8. Princ p1 p2 l1 l2 s2 Quarta Istruzione del main: Down p2 = new Down(); < Down p2 = new Down(); , 2 , s1 , x2 > com < 2 , s2 , x3 > x3 Up l1 m1' Down l2 m2' x=3; x=w;

  9. Quinta Istruzione del main: p2.met2(); < p2.met2(); , 2 , s2, x3 > com < 3 , s2 , x4> m2'(met2) = < -, {y = new Down(); y.x=x+1; y.met1()}, l2 > l1 /// Down y.x = x+1; l2 m2' In l2 x vale 7 l3 Down l3 m2'' x4'

  10. Quinta Istruzione del main: p2.met2(); < p2.met2(); , 2 , s2, x3 > com < 3 , s2 , x4> m2'(met2) = < -, {y = new Down(); y.x=x+1; y.met1()}, l2 > l1 /// m2''(met1) = < -, {x=x+w; w=0}, l3 > Down x = x + w; l2 m2' 8 7 Infine viene modificato l'ambiente delle classi: l3 Down m2'' 1'' 1''' x4

More Related