MilaDimitrovaa

Dog

Nov 16th, 2021
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. package com.company.newExercise;
  2.  
  3. public class Dog { //Opening class
  4.  
  5.     // Property definition
  6.     private String name;
  7.  
  8.     // Default-ен конструктор
  9.     public Dog( ) {
  10.         this.name = "Sharo";
  11.     }
  12.  
  13.     // Конструктор с параметри
  14.     public Dog(String name) {
  15.         this.name = name;
  16.     }
  17.  
  18.     // Get method
  19.     public String getName() {
  20.         return this.name;
  21.     }
  22.  
  23.     // Set method
  24.     public void setName(String name) {
  25.         this.name = name;
  26.     }
  27.     // Custom method - които ние създаваме
  28.     public void bark( ) {
  29.         System.out.printf("Dog %s said: Wow-wow!%n", name);
  30.     }
  31.  
  32. }//Closing class
  33.  
Advertisement
Add Comment
Please, Sign In to add comment