Skip to content

Instantly share code, notes, and snippets.

@mrnirva
Last active Sep 22, 2020
Embed
What would you like to do?
package encapsulation;
public class Kapsulleme {
public static void main(String[] args) {
Araba araba = new Araba();
araba.setRenk("Mavi");
araba.setRenk("Siyah");
araba.setTekerler(-5);
araba.setTekerler(4);
System.out.println(araba.getRenk());
System.out.println(araba.getTekerler());
}
}
class Araba{
// private olarak niteledik
private String renk;
private int tekerler;
// Sağ Tik -> Insert Code -> Getter and Setter
public String getRenk() {
return renk;
}
public void setRenk(String renk) {
if(renk.equals("Mavi")){
System.out.println("Mavi Renk Boya Kalmadı!");
}else{
this.renk = renk;
}
}
public int getTekerler() {
return tekerler;
}
public void setTekerler(int tekerler) {
if(tekerler < 4){
System.out.println("Geçersiz Giriş! -> "+tekerler);
}else{
this.tekerler = tekerler;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment