Java-Comment .

In this session i have discussed comment in Java .


The comment is used to provide the information to reader of program . The compiler ignore the comments . There are two types of comment in Java as follows .

1-Single line comment

2-Multiline comment


1-Single line comment

The single line comment is used to provide the information in a line . It is represented by doblue slash (//) .

In the below program comment is This program add the two numbers .

Example : Write a program that add two numbers with comment .

 public class Hello{ 
      
      public static void main(String args[]){  
       
         // add two number
         int x=20,y=10;
         int sum=x+y;
         System.out.println("Sum : "+sum);
     }  
 }  
    
    OUTPUT : Sum : 30
    

2-Mulitline comment

The multiline comment is used to provide the information in more than one line . It is represented by the slash with asterisk like this /* */ .

Example : Write a program that add two numbers with comment .

 public class Hello{ 
      
      public static void main(String args[]){  
       
            /*This program add the two numbers
            the program use two varibale x
            and y to sum and assign in sum
            variable */
            int x=20,y=10;
            int sum=x+y;
            System.out.println("Sum : "+sum);
      }  
 }  
    
    OUTPUT : Sum : 30
    

Welcome to AndroidATPoint.

back image                     next image