I got an error compiling the following code:
class TapeDeck
{
boolean canRecord = false;
void playTape()
{
System.out.println("tape playing");
}
void recordTape()
{
System.out.println("tape recording");
}
}
class TapeDeckTestDrive
{
public static void main(String [] args)
{
TapeDeck t;
t.canRecord = true;
t.playTape();
if(t.canRecord == true)
{
t.recordTape();
}
}
}
The error is:
TapeDeck.java:21: error: variable t might not have been initialized
t.canRecord = true;
^
1 error
How shall I initialize the variable t in the class?