Created
December 8, 2020 05:16
-
-
Save ucguy4u/59d9401e0e5bf707bd18fbc7a036e60a to your computer and use it in GitHub Desktop.
Inheritance example using getter and setters
This file contains hidden or 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
class Bank { | |
private String bankName; | |
public Bank(String bankName) { // constructor | |
this.bankName = bankName; | |
} | |
public String getBankName() { // getter | |
return this.bankName; | |
} | |
} | |
public class Employee extends Bank{ | |
public Employee(String bankName) { | |
super(bankName); | |
} | |
public static void main(String[] args){ | |
Bank bank = new Bank("Axis"); | |
System.out.println("Riya works for : " + | |
bank.getBankName()); | |
// we are not accessing the private member directly we are instead using public getter setter to access the private member. | |
} | |
} | |
/** | |
* OUTPUT: | |
* Riya works for : Axis | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment