Created
September 5, 2020 23:32
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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