go to previous page   go to home page   hear noise   go to next page

Answer:

Yes, although it is ugly and not commonly done.


Commenting Out Code

class BuggyHaiku
{
  public static void main ( String[] args )
  {
    System.out.println("On a withered branch" );
/*
    System.out.println("A crow has just alighted:");
    System.out.println("Nightfall" in autumn.");
*/
  }
}

Comments are useful for debugging. For example, the above program has a syntax error. Let's say that you are having problems finding the error. One way to narrow down the problem is to remove some of the code from consideration by turning it into a comment. Compile and run the program.

If the modified program works as expected, the error must be in the commented section. Gradually decrease the commented section until you find the error.


QUESTION 18:

What is the error in the program? (Click for a hint.)

Why would you ever want to use comments to help a person understand your program?