Untitled
class User { private int level= 1; private int canSeeProfiles = 1; public int canBuyThings= 1; private int canSellThings= 1; public User(int level, int canSeeProfiles, int canBuyThings, int canSellThings) { this.level = level; this.canSeeProfiles = canSeeProfiles; this.canBuyThings = canBuyThings; this.canSellThings = canSellThings; } //yukarisi constructorlar // getterler public int getLevel() { return level; } public int getCanSeeProfiles() { return canSeeProfiles; } public int getCanBuyThings() { return canBuyThings; } public int getCanSellThings() { return canSellThings; } //setter örneği var burda public void setCanBuyThings(int canBuyThings) { this.canBuyThings = canBuyThings; } } // üst classı extendliyo class NormalUser extends User { public NormalUser(){ super(1,1,1,1); } } //bu silverlerin hepsi normallerin özelliklerine de sahip o yüzden extendliyo gold da silveri extendlicek class SilverUser extends User { public SilverUser() { super(2, 2, 1, 1); } } class GoldUser extends SilverUser { public GoldUser() { super(); } @Override public int getCanBuyThings() { return 4; } // Veya // sonra kod içerisinde setter } public class Main { public static void main(String[] args) { GoldUser gu = new GoldUser(); System.out.println("\nGoldUser"); System.out.println("Can Sell Things: " + gu.getCanSellThings()); System.out.println("Can Buy Things: " + gu.getCanBuyThings()); System.out.println("LeveL: " + gu.getLevel()); NormalUser nu = new NormalUser(); System.out.println("\nNormalUser"); System.out.println("Level: " + nu.getLevel()); System.out.println("Can Sell Things: " + nu.getCanSellThings()); System.out.println("Can Buy Things: " + nu.getCanBuyThings()); SilverUser su = new SilverUser(); su.setCanBuyThings(2); System.out.println("\nSilverUser"); System.out.println("Level: " + su.getLevel()); System.out.println("Can Buy Things: " + su.getCanBuyThings()); System.out.println("Can Sell Things: " + su.getCanSellThings()); } }
Leave a Comment