I am a new student in computer programming. I watched a video about Java, the main composition, and the guy in the video made an example on this subject as follows:
public class PaperTray
{
int pages = 0;
....
public boolean isEmpty()
{
return pages > 0;
}
}
public class Printer extends Machine
{
private PaperTray paperTray = new PaperTray();
....
public void print(int copies)
{
....
while(copies > 0 && !paperTray.isEmpty() )
{
System.out.println("some text to print");
copies--;
}
if(paperTray.isEmpty())
{
System.out.println("load paper");
}
}
My question is that the paper tray is empty and then in the PaperTray class the isEmpty () method will return false. Therefore, the if statement in the Printer class will not be executed. And if the paper tray is not empty, the isEmpty () method in the PaperTray class will return true, so the while statement in the Printer class will not be executed. Am I mistaken, or did the instructor in the video make some mistakes?
thank
source
share