Licence d'informatique |
Programmation objet et Java
|
public int f(int y) {
int x = y + 2;
return y;
}
public int h(int y) {
int x = y + 4;
return x;
}
public static void main(String[] args) {
x = 2;
x = f(h(2));Que vaut x ?
(a) 0
(b) 5
(c) 7
(d) 9
(e) Il y a erreur à la compilation
public static void main(String[] args) {
int x = 6;
x = (x == 6) ? 5 : 7;
int j = 0;
for (; j < 4; j++)
j += x;Que vaut x après la boucle ?
(a) 6 (b) 5 (c) 7 (d) 12 (e) Il y a erreur à la compilation
static void f(Personne p, String n) {
p.nom = n;
}puis on appelle
Personne p = new Personne("Alain", 24);
f(p, "Paul");
(a) le champ p.nom vaut "Paul"
(b) le champ est inchangé
(c) l'écriture est illégale.
System.out.println(3 + "" + 4);(a) 7 (b) 34 (c) 3 4 (d) 43
class Prince {
public static void main(String[] args) {
System.out.println(
id(false, 1) || id(false, 2) || id(true, 3) || id(false, 4));
}
static boolean id(boolean b, int i) {
System.out.print(i);
return b;
}
}
(a) 43true (b) 123true (c) 1234true (d) 12false
(a) for (int i = 0; i < tab.length(); i++)
(b) for (int k = tab.length - 1; k > - 1; k--)
(c) for (int i = 1; i < tab.length; i++)
(d) for (int p = tab.length() - 1; p >= 0; p--)
(a) vrai
(b) faux
static boolean guu(int a, int b) {
if (a <= b)
return b % 2 == 0;
if (a % 2 == 0)
return a == b;
return a != b;
}
(a) true true (b) true false (c) false true (d) false false
class Chose {
static void faire(int n) { n += 4; }
public static void main(String[] args) {
int n = 3;
faire(n);
faire(n + 1);
}
}(a) Une constante.
(b) Un paramètre
(c) Une variable
(d) Un attribut
(a) Un attribut de l'objet
(b) Une variable locale à la méthode
(c) Une variable globale
class MonExemple {
private boolean b = true;
boolean maMéthode(boolean local) {
local = !local;
return (local == b);
}public static void main(String[] args) {
test monExemple = new MonExemple();
monExemple.b = monExemple.maMéthode(monExemple.b);
System.out.println(monExemple.b);
}
}(a) Le résultat est true
(b) Le résultat est false
(c) Il y a erreur à la compilation