Object-Oriented Java

Using Methods: I

Great! Now the bark method is available to use on the spike object. We can do this by calling the method on spike.

Here is an example of calling a method on an object using the Car class:

class Car {

    int modelYear;

    public Car(int year) {

        modelYear = year;


    public void startEngine() {



    public static void main(String[] args){

        Car myFastCar = new Car(2007);

In the example above, we call the startEngine method on the myFastCar object. Again, this occurs inside of the main method. Running the program results in printing Vroom! to the console.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.