Java Tutorial Lesson 03: non static methods

From Erlands Wiki

Jump to: navigation, search

This lesson is similar to the previous one, the difference is just that the declaration of the print method is a little bit different.

Start with a java class “Game” that looks as follows:

public class Game {
    private void print() {
        System.out.println("----------");
        System.out.println("|        |");
        System.out.println("|        |");
        System.out.println("|        |");
        System.out.println("----------");
    }
}

Your job is to implement the main method so the class can be called with:

java Game

And generate the output:

Lesson 3
 
----------
|        |
|        |
|        |
----------
Personal tools