Boyan5

OOP1 class Dog

Nov 16th, 2021
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. // Class declaration
  2. public class Dog { // Opening brace of the class body
  3.  
  4.     // Field ( Property ) definition
  5.     private String name;
  6.  
  7.     // Constructor definition DEFAULT
  8.     public Dog() {
  9.         this.name = "Sharo";
  10.     }
  11.  
  12.     // Constructor definition WITH PARAMETERS
  13.     public Dog(String name1) {
  14.         this.name = name1;
  15.     }
  16.  
  17.     // Property getter-method definition /GETTERS/
  18.     public String getName( ) {
  19.         return this.name;
  20.     }
  21.  
  22.     // Property setter-method definition /SETTERS/
  23.     public void setName(String name1) {
  24.         this.name = name1;
  25.     }
  26.  
  27.  
  28.     // Method definition CUSTOM
  29.     public void bark( ) {
  30.         System.out.printf("Dog %s said: Wow-wow! %n", name);
  31.     }
  32. } // Closing brace of the class body
  33.  
Advertisement
Add Comment
Please, Sign In to add comment