Created
September 19, 2013 06:40
-
-
Save omatt/6619800 to your computer and use it in GitHub Desktop.
Simple implementation of the Object Oriented Concept - Encapsulation
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
/** | |
* Sample for Object Oriented Programming Concepts | |
* | |
* Encapsulation | |
* | |
* @author Reyes, Omar Matthew B. | |
* @version 2013/09/07 | |
*/ | |
public class EncapsulationSample{ | |
private String name; | |
private String address; | |
private int age; | |
// Objects that allows private variables be accessed by other classes | |
/** "Getter" methods or accessor **/ | |
public String getName(){ | |
return name; | |
} | |
public String getAddress(){ | |
return address; | |
} | |
public int getAge(){ | |
return age; | |
} | |
// Set variable values that can be accessed from other classes. | |
/** "Setter" methods or mutator **/ | |
public void setName(String newName){ | |
name = newName; | |
} | |
public void setAddress(String newAddress){ | |
address = newAddress; | |
} | |
public void setAge(int newAge){ | |
age = newAge; | |
} | |
} |
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
/** | |
* Sample for Object Oriented Programming Concepts | |
* | |
* Encapsulation | |
* | |
* @author Reyes, Omar Matthew B. | |
* @version 2013/09/07 | |
*/ | |
public class RunEncapsulation{ | |
public static void main(String [] args){ | |
EncapsulationSample encap = new EncapsulationSample(); | |
encap.setName("Omar"); | |
encap.setAddress("Quezon City"); | |
encap.setAge(20); | |
System.out.println("Name: " + encap.getName() + "\nAddress: " | |
+ encap.getAddress()+"\nAge: "+encap.getAge()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment