OCP

Pour quelle classe la méthode main compilerai ?
 
public static void main(String[] args) {
BigCat cat = new BitCat();
System.out.println(cat.name);
}

package cat;
public class BigCat {
public String name = "cat";
}

package cat.species;
public class Lynx extends BigCat {}

package cat;
public class CatAdmirer {}

package mouse;
public class Mouse {}
BigCat
Lynx
CatAdmirer
Mouse
Pour quelle classe la méthode main compilerai ?
 
public static void main(String[] args) {
BigCat cat = new BitCat();
System.out.println(cat.hasFur);
}

package cat;
public class BigCat {
protected boolean hasFur = true;
}

package cat.species;
public class Lynx extends BigCat {}

package cat;
public class CatAdmirer {}

package mouse;
public class Mouse {}
BigCat
Lynx
CatAdmirer
Mouse
Pour quelle classe la méthode main compilerai ?
 
public static void main(String[] args) {
BigCat cat = new BitCat();
System.out.println(cat.hasPawn);
}

package cat;
public class BigCat {
boolean hasPawn = true;
}

package cat.species;
public class Lynx extends BigCat {}

package cat;
public class CatAdmirer {}

package mouse;
public class Mouse {}
BigCat
Lynx
CatAdmirer
Mouse
Pour quelle classe la méthode main compilerai ?
 
public static void main(String[] args) {
BigCat cat = new BitCat();
System.out.println(cat.hasPawn);
}

package cat;
public class BigCat {
private int id;
}

package cat.species;
public class Lynx extends BigCat {}

package cat;
public class CatAdmirer {}

package mouse;
public class Mouse {}
BigCat
Lynx
CatAdmirer
Mouse
Quel ligne est une redéfinition ?
 
class Bobcat {
public void findDen() { }
}

class BobcatKitten extends Bobcat {
public void findDen() { }
public void findDen(boolean b) { }
public int findden() throws Exception { return 0; }
}
2
5
6
7
Quel ligne est une surcharge ?
class Bobcat {
public void findDen() { }
}

class BobcatKitten extends Bobcat {
public void findDen() { }
public void findDen(boolean b) { }
public int findden() throws Exception { return 0; }
}
2
5
6
7
Quel(les) ligne(s) ne compile(nt) pas ?
 
class Bobcat {
public void findDen() { }
}

class BobcatKitten extends Bobcat {
public void findDen() { }
public void findDen(boolean b) { }
public int findden() throws Exception { return 0; }
}
Aucune
2
4
5
6
7
Par quel ligne peut-on remplacer la ligne en pointillé ?
 
abstract class Cat {
---------------------
}

class Lion extends Cat {
void clean() {}
}
Rien
Public abstract void clean();
Void clean() {}
Default void clean {}
Sur quelle(s) ligne(s) peut-on ajouter des mots clés 'final' ?
abstract class Cat {
String name = "The Cat";
void clena() {}
}
class Lion extends Cat {
void clean() {}
}
1
2
3
5
6
Sur quelle(s) ligne(s) peut-on ajouter des mots clés 'static' ?
 
abstract class Cat {
String name = "The Cat";
void clean() {}
}
class Lion extends Cat {
void clean() {}
}
1
2
3
5
6
3 & 6 en même temps
1 & 5 en même temps
Quelle(s) import(s) est (sont) obligatoire pour que le code compile ?
 
class ListHelper {
public List<String> copyAndSortList(List<String> original) {
List<String> list = new ArrayList<String>(original);
sort(list);
return list;
}
}
Import java.util.*;
Import java.util.Collections.*;
Import java.lang.String;
Import java.lang.*;
Import static java.util.ArrayList;
Que va afficher le code suivant ?
 
static class HeavyAnimal {}
static class Hippo extends HeavyAnimal {}
static class Elephant extends HeavyAnimal {}

public static void main(String[] args) {
HeavyAnimal heavyAnimal = new Hippo();
Hippo hippo = new Hippo();
Elephant elephant = new Elephant();
System.out.println(heavyAnimal instanceof HeavyAnimal);
System.out.println(heavyAnimal instanceof Hippo);
System.out.println(heavyAnimal instanceof Elephant);
System.out.println(hippo instanceof HeavyAnimal);
System.out.println(hippo instanceof Hippo);
}
Truetruefalsetruetrue
Truefalsefalsefalsetrue
Truefalsefalsetruetrue
Le code ne compile pas
Que va afficher le code suivant ?
 
static class HeavyAnimal {}
static class Hippo extends HeavyAnimal {}
static class Elephant extends HeavyAnimal {}

public static void main(String[] args) {
HeavyAnimal heavyAnimal = new Hippo();
Hippo hippo = new Hippo();
Elephant elephant = new Elephant();
System.out.println(heavyAnimal instanceof Hippo);
System.out.println(heavyAnimal instanceof Elephant);
System.out.println(elephant instanceof HeavyAnimal);
System.out.println(elephant instanceof Hippo);
}
Falsefalsefalsefalse
Truefalsetruefalse
Falsefalsetruefalse
Le code ne compile pas
Que va afficher le code suivant ?
 
interface Mother {}
static class HeavyAnimal {}
static class Hippo extends HeavyAnimal {}
static class Elephant extends HeavyAnimal {}

public static void main(String[] args) {
HeavyAnimal heavyAnimal = new Elephant();
Hippo hippo = new Hippo();
Elephant elephant = new Elephant();
System.out.println(heavyAnimal instanceof Mother);
System.out.println(heavyAnimal instanceof Elephant);
System.out.println(elephant instanceof HeavyAnimal);
System.out.println(elephant instanceof Mother);
}
Falsetruetruefalse
Truefalsefalsetrue
Falsefalsefalsefalse
Le code ne compile pas
{"name":"OCP", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Pour quelle classe la méthode main compilerai ?   public static void main(String[] args) { BigCat cat = new BitCat(); System.out.println(cat.name);}package cat;public class BigCat { public String name = \"cat\";}package cat.species;public class Lynx extends BigCat {}package cat;public class CatAdmirer {}package mouse;public class Mouse {}, Pour quelle classe la méthode main compilerai ?   public static void main(String[] args) { BigCat cat = new BitCat(); System.out.println(cat.hasFur);}package cat;public class BigCat { protected boolean hasFur = true;}package cat.species;public class Lynx extends BigCat {}package cat;public class CatAdmirer {}package mouse;public class Mouse {}, Pour quelle classe la méthode main compilerai ?   public static void main(String[] args) { BigCat cat = new BitCat(); System.out.println(cat.hasPawn);}package cat;public class BigCat { boolean hasPawn = true;}package cat.species;public class Lynx extends BigCat {}package cat;public class CatAdmirer {}package mouse;public class Mouse {}","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker