Skip to content

Instantly share code, notes, and snippets.

@mrnirva
Created September 5, 2020 23:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mrnirva/390e0ab1378285445c59a57745ef2ac1 to your computer and use it in GitHub Desktop.
package accessmodifiers;
public class ErisimBelirleyiciler {
public static void main(String[] args) {
Cocuk cocuk = new Cocuk();
// boy'a veya sacRengine artık erişimimiz yok
// Çünkü ikiside private sadece Baba sınıfına aitler
// cocuk.boy = 180;
// Ekrana yazdırmaya çalışırsak hata alırız
// System.out.println("Çocuk Boyu: "+cocuk.boy);
// Bu metot protected olduğu için halen buna erişim sağlanabilir
cocuk.dil();
}
}
class Baba{
// Bu özellikleri private olarak güncelledik
private int boy;
private String sacRengi;
// Bunu protected olarak bıraktık
protected void dil(){
System.out.println("Türkçe");
// Boy'a buradan erişebiliriz
boy = 190;
// sacRengi'ne buradan erişebiliriz
sacRengi = "Kahverengi";
// Yani private öğelere sadece sınıf içerisinden erişim yapılabilir
}
}
class Cocuk extends Baba{
// Görüldüğü gibi protected'a halen erişebiliyoruz
@Override
protected void dil() {
System.out.println("İngilizce");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment