1 / 8

Si consideri il seguente programma: class Up extends Object { public static int x;

Si consideri il seguente programma: class Up extends Object { public static int x; public int y; public static void metodo(Up o) {Up w=o.metodo1(x); o.y=w.y+6;} public Up metodo1 (int i) {Up w = new Up(); w.y = x + 5; y=y+1;return w;} {x=1; y=x+3;} }

rhett
Download Presentation

Si consideri il seguente programma: class Up extends Object { public static 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. Si consideri il seguente programma: class Up extends Object { public static int x; public int y; public static void metodo(Up o) {Up w=o.metodo1(x); o.y=w.y+6;} public Up metodo1 (int i) {Up w = new Up(); w.y = x + 5; y=y+1;return w;} {x=1; y=x+3;} } class Down extends Up { public static int z; public Up metodo1(int i) {Up w = new Down(); w.y=z-w.x; y= w.y+x; return w;} {z=3;y=z-1;} } class Princ extends Object { public static void main(){ Up p1 = new Down(); Up p2=new Up(); p2.metodo(p1); p2.metodo(p2);} } Si mostri lo stato (ambiente di classi, heap, pila) dopo l'esecuzione di ciascuna istruzione di main.

  2. Ambiente delle classi 0 Nome classe Classe ereditata Variabili e metodi statici Variabili e metodi non statici Princ Object Down Up DescrUp z 0 y 0 Down DescrDown Up 3 4 metodo1 Descrmetodo1 m3 Up y 0 Up DescrUp x 0 metodo Descrmetodo metodo1 Descrmetodo1 2 Object m1 1 m2 Object

  3. Ereditarieta' sul costruttore Ambiente delle classi 0 Descrmetodo = < Up o, {Up w=o.metodo1(x); o.y=w.y+6;},Up> Descrmetodo1 = <int i, {Up w = new Up(); w.y = x + 5; y=y+1;return w;}, Up> DescrUp = <-, {x=1; y=x+3;}, Up> Descrmetodo1 = <int i, {Up w = new Down(); w.y=z-w.x; y= w.y+x; return w;}, Down> Overriding del metodo metodo1 DescrDown = <-, {x=1;y=x+3; z=3;y=z-1}, Down>

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

  5. z x y 1 2 3 Prima istruzione del main: Up p1 = new Down() < Up p1 = new Down();,0 , s0 , x0 > com < 1 , s1 , x1 > Princ Down l1 p1 l1 x1 m3' s1 1

  6. z x y y 2 4 3 1 Seconda istruzione del main: Up p2 = new Up() < Up p2 = new Up();1 , s1 , x1> com < 1 , s2 , x2 > Down l1 Princ m3' p1 l1 p2 l2 l2 Up s2 m2' x2 1

  7. y y y z x 8 4 1 2 3 Terza istruzione del main: p2.metodo(p1) < p2.metodo(p1);1 , s2 , x2> com < 1 , s2 , x3 > Down l1 m3' Princ p1 l1 Up p2 l2 l2 m2' s2 Down l3 x3 m3'' 1

  8. y y y x z y 2 1 3 12 8 6 Quarta istruzione del main: p2.metodo(p2) < p2.metodo(p2);1 , s2 , x3> com < 1 , s2 , x4 > Down l1 m3' Princ Up p1 l1 l2 m2' p2 l2 s2 Down l3 m3'' Up 1 l4 m2'' x4

More Related