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) { | |
// Bir çocuk nesnesi oluşturduk | |
Cocuk cocuk = new Cocuk(); | |
// Buradan Baba'da olan bir özelliğe rahatlıkla eriştik | |
cocuk.boy = 180; | |
// Değer atadığımız özelliği yazdırdık | |
System.out.println("Çocuk Boyu: "+cocuk.boy); | |
// Aynı şekilde babadan alıp değiştirdiğimiz metoduda çağırabildik | |
cocuk.dil(); | |
} | |
} | |
// Baba isimli sınıfımız | |
class Baba{ | |
protected int boy; | |
protected String sacRengi; | |
protected void dil(){ | |
System.out.println("Türkçe"); | |
} | |
} | |
// Babadan miras alan Cocuk sınıfımız | |
class Cocuk extends Baba{ | |
@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