|
1. Ce puteţi spune despre subprogramul alăturat? | |
|
|
double x = 0; if (Double.isInfinite(2 / x)) System.out.println("infinit"); else System.out.println("2 / 0"); |
|
2. Ce va afişa la execuţie programul alăturat? | |
|
|
public class Asignare { public static void main(String args[]) { int a = 3; int b = (a = 2) * a; int c = b * (b = 5); System.out.println( "a = " + a + ", b = " + b + ", c = " + c); } }
|
|
3. Ce puteţi spune despre următorul programul alăturat? | |
|
|
class C1 { public String f() { return this.getClass().getName(); } } abstract class C2 extends C1 { int x = 2; public abstract String f(); } class C3 extends C2 { int y = 3; public String f() { return super.f() + ", x = " + x + ", y = " + y; } } public class TestAbstract { public static void main(String args[]) { C3 obiect = new C3(); System.out.println(obiect.f()); } } |
|
4. Care din afirmaţiile de mai jos sunt adevărate ? | |
|
| |
|
5. Ce puteţi spune despre programul alăturat? | |
|
|
class C1 { static String f() { return "Mesajul Unu din C1"; } String g() {return "Mesajul Doi din C1";} } class C2 extends C1 { static String f() { return "Mesajul Unu din C2"; } String g() {return "Mesajul Doi din C2";} } public class Test { public static void main(String[] args) { C1 obiect = new C2(); System.out.println( obiect.f() + ", " + obiect.g()); } }
|
|
6. Ce puteţi spune despre programul alăturat? | |
|
|
class C1 { int x = 1; C1(int x) { this.x = x; } } class C2 extends C1 { int y = 3; C2(int x) {this(x, y);} C2(int x, int y) {super(x);this.y = y;} public String toString() { return "x = " + x + ", y = " + y; } } public class Test { public static void main(String args[]) { C2 obiectUnu = new C2(4); C2 obiectDoi = new C2(5, 6); System.out.print(obiectUnu + " "); System.out.println(obiectDoi); } }
|
|
7. Ce puteţi spune despre programul alăturat? | |
|
|
interface I1 { int j = 3; int [] i = {j + 1, j + 2}; } interface I2 { int j = 5; int [] i = {j + 2, j + 4}; } public class Test implements I1, I2 { public static void main(String[] args) { System.out.print(I1.j + " "); System.out.print(I2.i[1] + " "); System.out.print(I1.i[0]); } }
|
|
8. Ce se poate spune despre subprogramul Java alăturat? | |
|
|
int i = 1, suma = 0; for ( ; ; ) { suma += i++; if (i > 5) break; } System.out.print(suma);
|
|
9. Ce puteţi spune despre programul alaturat? | |
|
|
class C1 { int x = 1; void f(int x) { this.x = x; } int getX_C1() { return x; } } class C2 extends C1 { float x = 5.0f; int f(int x) { super.f((int)x); } float getX_C2() { return x; } } public class SuprascriereSiAscundere { public static void main(String args[]) { C2 obiect = new C2(); obiect.f(4); System.out.print(obiect.getX_C2()+ " "); System.out.println(obiect.getX_C1()); } }
|
|
10. Presupunem că avem un fragment de cod Java dintr-o aplicaţie care are drept de scriere īn directorul de lucru curent şi că īn directorul curent nu există fişierul numit "fisier.txt". Care va fi rezultatul compilării şi execuţiei codului alăturat? | |
|
|
1 try { 2 RandomAccessFile f1 = new RandomAccessFile("fisier.txt", "rw"); 3 BufferedOutputStream f2 = new BufferedOutputStream(f1); 4 DataOutputStream f3 = new DataOutputStream(f2); 5 f3.writeDouble(Math.PI); 6 f3.close(); 7 f2.close(); 8 f1.close(); 9 } catch(IOException e) { } |