Vivek Memory Box
» Example 2
« Previous
|
Next »
[Start Over]
Explanation
The program has started. The first event that now occur is for the class loader will load all the classes into the static region.
c:\>java CharityGame
Source Code
class Game
{
public static int pointsEarned;
public Game()
{
pointsEarned++;
}
}
class CharityGame extends Game
{
public static int pointsEarned;
public CharityGame()
{
pointsEarned++;
}
public static void main(String[]args)
{
Game game7 = new Game();
CharityGame cb2 = new CharityGame();
System.out.println(game7.pointsEarned);
System.out.println(cb2.pointsEarned);
System.out.println(CharityGame.pointsEarned);
System.out.println(Game.pointsEarned);
}
}