Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Class declaration
- public class Dog { // Opening brace of the class body
- // Field ( Property ) definition
- private String name;
- // Constructor definition DEFAULT
- public Dog() {
- this.name = "Sharo";
- }
- // Constructor definition WITH PARAMETERS
- public Dog(String name1) {
- this.name = name1;
- }
- // Property getter-method definition /GETTERS/
- public String getName( ) {
- return this.name;
- }
- // Property setter-method definition /SETTERS/
- public void setName(String name1) {
- this.name = name1;
- }
- // Method definition CUSTOM
- public void bark( ) {
- System.out.printf("Dog %s said: Wow-wow! %n", name);
- }
- } // Closing brace of the class body
Advertisement
Add Comment
Please, Sign In to add comment