java java java -il

annuncio pubblicitario
A
Test 1
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
Test 2
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
java A
public class A {
public static void main(String g[]){
int a=2;
Int b=new Int(3);
f(a); f(b);
System.out.println(a+" "+b);
}
static void f(int k){ k++;}
static void f(Int v){ v.k++; }
}
class Int{
int k;
Int(int k){this.k=k;}
public String toString(){return ""+k;}
}
java B
public class B {
String a[10];
void initialize(){
for (int k=9;k>=0;--k) a[k]=""+k;
}
void stampa(int k){
System.out.println(a[k]);
}
B() {initialize(); stampa(0); }
public static void main(String a[]){
new B();
}
public static void main(String a){
new B();
}
}
Test 3
01
02
03
04
05
06
07
08
09
10
11
12
13
#include <iostream.h>
int k=2;
void f( int m ) { m=m*2; }
void g( int *m ) { m++; }
void h( int m[4] ) { m[0]--; }
void p(){cout<<k;}
int main(){
int k=5;
g(&k);h(&k);f(k);
cout << k;
p();
return 0;
}
A
Test 4
00
01
02
05
06
07
08
09
10
11
Test 5
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
java B
class B {
static int s=0;
B(int i){s=i;}
public static void main(String[] args) {
B b1=new B(3);
B b2=new B(3);
B b3=new B(1);
if (b1.equals(b2)) System.out.print("B"); else
System.out.print("A");
if (b1.s==b3.s) System.out.print("D"); else
System.out.print("C");
}
}
java D
class A {
A(int x) {System.out.print("T");}
A() {System.out.print("S");}
public void finalize() {System.out.print("U");}
}
public class D extends A {
D(int x) {System.out.print("F");}
D() {System.out.print("H");}
public void finalize() {System.out.print("G");}
public static void main(String args[]) {
A a=new D(3);
a = null;
System.gc();
System.runFinalization();
}
}
Test 6
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
package uno;
public class A {
void f(int k) {
System.out.print(k*3);
}
public static void main (String args[]){
Object z = new B();
if (z instanceof uno.A) ((A) z).f(1);
if (z instanceof uno.B) ((B) z).f(2);
}
}
class B extends A{
void f(int k) {
System.out.print(k*2);
}
}
A
Test 7
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
import java.util.*;
public class Cinque {
Collection z;
public Cinque(int k) {
if (k==0) z = new HashSet();
else z=new LinkedList();
}
public static void main(String[] args) {
Cinque a = new Cinque(1);
Cinque b = new Cinque(0);
for (int k=0;k<10;k++){
Integer z=new Integer(k%4);
a.z.add(z);
b.z.add(z);
}
System.out.println(a.z.size()+b.z.size());
}
}
Test 8
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
import java.util.*;
public class Cinque {
static Collection z;
public Cinque(int k) {
if (k==0) z = new HashSet();
else z=new LinkedList();
}
public static void main(String[] args) {
Cinque a = new Cinque(1);
Cinque b = new Cinque(0);
for (int k=0;k<10;k++){
Integer z=new Integer(k%4);
a.z.add(z);
b.z.add(z);
}
System.out.println(a.z.size()+b.z.size());
}
}
Test 9 – scrivere nel campo per l’output del test la sequenza risultante indicando T per
le affermazioni vere e F per quelle false. Tutte le affermazioni, ove non altrimenti
specificato, riguardano Java.
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
In Java non esistono le variabili globali
Java usa solo la heap e non lo stack
In C++ le variabili globali stanno in Heap
Una classe figlia può fare l’overloading di un metodo protetto della classe padre
Una classe figlia può fare overriding di un metodo protetto della classe padre
Se una classe è astratta è permesso usarla per effettuare ereditarietà multipla
Java non prevede l’ereditarietà multipla
Se una Collection è specializzata tramite una generic gli oggetti estratti dal relativo
iteratore non richiedono un cast.
A
Scarica