# Introduction to Objects

View Source View Source

1. Create a Duck class in your java project. Add its member variables and methods to match the picture above. Now add the code for the constructor of the Duck class: Duck(String favoriteFood, int numberOfFriends) { this.favoriteFood = favoriteFood; this.numberOfFriends = numberOfFriends; } 2. Now pick your favorite animal and describe it with at least 2 member variables and 2 methods.
  1. Create a java class for your animal including: member variables methods(with sysouts) a constructor that sets the member variables

  2. Create a new java class. This will be a "runner" or "driver" class, so it will need a main method.

  3. In your runner class, create a Duck object (instance) by calling its constructor as follows: Duck daffy = new Duck("donuts",5); Now you have a duck object, you can make it quack: daffy.quack();

  4. Now create an instance of your animal (Hint: see step 5 above) and call its methods.