Académique Documents
Professionnel Documents
Culture Documents
EX 1:
1- On crée un objet nommé P, println affiche 00 car les attributs x et y n'ont
aucune valeur.
2- Le problème est que les propriétés x et y sont privées donc elles ne sont
utilisées que dans les points de classe, la solution est d'utiliser fct getter.
3- L'utilisation d'accesseurs en Java n'est pas obligatoire mais est une question
de conception et de besoins spécifiques. Il est crucial de trouver un
équilibre entre encapsulation et simplicité pour chaque classe de votre
programme.
private int x;
private int y;
this.x = px;
this.y = py;
}}
private int x;
private int y;
public Point() {
this.x = 0;
this.y = 0;
}} }
Le code :
private int x;
private int y;
this.x = px;
this.y = py;
this.x = point.x;
this.y = point.y;
}}
EX2:
public class Book {
String title;
String author;
String isbn;
double price;
Book(String title, String author, String isbn,
double price) {
this.title = title;
this.author = author;
this.isbn = isbn;
this.price = price;
System.out.println(book);
}
}
EX3:
public class Ex3 {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("entre une chaine");
String ch=sc.nextLine();
String newCh="";
for(int i=ch.length()-1;i>=0;i--) {
newCh=newCh+ch.charAt(i);
}
System.out.println(newCh);
}