Looking for Programmation Java et IHM test answers and solutions? Browse our comprehensive collection of verified answers for Programmation Java et IHM at cours.cyu.fr.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Comment empêcher une classe d’être héritée en Java ?
class A {
int x = 10;
void afficher() {
System.out.println("A");
}
}
class B extends A {
int x = 20;
void afficher() {
System.out.println("B");
}
}
public class Test {
public static void main(String[] args) {
A obj = new B();
System.out.println(obj.x);
obj.afficher();
}
}
Quelle est la différence entre une classe abstraite et une interface après Java 8 ?
class Parent {
static void afficher() {
System.out.println("Parent");
}
}
class Enfant extends Parent {
static void afficher() {
System.out.println("Enfant");
}
}
public class Test {
public static void main(String[] args) {
Parent p = new Enfant();
p.afficher();
}
}
public interface Max {
public double max( );
public int nombreElements
}
public final interface Stats extends Max{
public double somme( );
}
public class Groupe extends Stats {
private double[] valeurs = {3.2, 8.5, 6.1, 1.5, 2.8};
public double max
double maximum = valeurs[0];
for(int i=1; i < valeurs.length; i++) {
if (valeurs[i] > maximum) maximum = valeurs[i];
}
return maximum;
}
public double somme
double accum = 0.0;
for(int i=0; i < valeurs.length ; i++)
accum+=valeurs [i];
return accum;
}
public double get(int index) { return valeurs[index]; }
public static void main(String[] args) {
Groupe mmGroupe = new Groupe();
System.out.println("Max mmGroupe " + mmGroupe.max
System.out.println("somme mmGroupe " + ((Stats) mmGroupe).somme());
System.out.println("dernier element " + mmGroupe.get(7) );
}
}
|
a) Dans le code, il y a quatre erreurs, trouvez-les. Justifiez votre réponse.
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!