Last active
November 5, 2020 11:57
-
-
Save kertnik05/efef4212505398e33de8d3652e266d69 to your computer and use it in GitHub Desktop.
Encapsulation
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
| public class Driver | |
| { | |
| public static void main(String[] args) | |
| { | |
| Person person = new Person(); | |
| person.setName("John Wick"); | |
| person.setAge(30); | |
| System.out.println("Person name is: " + person.getName()); | |
| System.out.println("Person age is: " + person.getAge()); | |
| } | |
| } |
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
| public class Person | |
| { | |
| private String name; | |
| private int age; | |
| public void setName(String name) | |
| { | |
| this.name = name; | |
| } | |
| public void setAge(int age) | |
| { | |
| this.age = age; | |
| } | |
| public String getName() | |
| { | |
| return this.name; | |
| } | |
| public int getAge() | |
| { | |
| return this.age; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment