Final practice example PDF

Title Final practice example
Author Tim Shelton
Course Introduction to Algorithms and Programming and Lab
Institution California State University Northridge
Pages 4
File Size 57.9 KB
File Type PDF
Total Downloads 31
Total Views 156

Summary

COMP 110 (Orientation to Computer Science) – FALL 2017
Dr. Wen-Chin (Amy) Hsu
...


Description

A dog class:

public class Dog{ //variables: private int age; private String name; // Constructor: public Dog(){ name = "lisa"; age = 0; }//end constructor 1 public Dog(String name){ this.name = name; this.age = 0; }// end constructor 2 public Dog(String name, int age){ this.name = name; this.age = age; }//end constructor 3 // Getter and setter: public String getName(){ return name; } public void setName(String name){ this.name = name; } public int getAge(){ return age; } public void setAge(int age){ this.age = age; } // Override method: /**/ public String toString(){ return " my name is " + this.getName() + " and i am " + this.getAge() + " years old!";

} //...


Similar Free PDFs