Object Programming  «Prev  Next»

Creating a simple class - Exercise

Objective:Develop the source code for a simple Java class and method.

Exercise grading

This exercise is worth a total of 1 point.

Exercise instructions

  1. Write the class definition source code for a class named Snake that contains three member variables:
    1. a member variable named length of type int
    2. a member variable named aggression of type int
    3. a member variable named poisonous of type boolean
  2. Write the source code for a method named isPoisonous() that is part of the Snake class. The isPoisonous() method should return a type boolean, accept no parameters, and use the poisonous member variable as its return argument.

After completing the exercise, click the Submit button and the system will award you full credit.