Java OCA OCP Practice Question 1519

Question

The options below contain the complete contents of a file (the name of the file is not specified).

Which of these options can be run with the following command line once compiled?

java main 

Select 1 option

A.  //in file main.java 

class main  { //from  w w  w. j a va2  s  .co m
   public void main (String [] args)  { 
       System.out.println ("hello"); 
    } 
} 
B.  //in file main.java 

   public static void main4 (String [] args)  { 
       System.out.println ("hello"); 
    } 
C.  //in file main.java 

public class anotherone{ 
} 
class main  { 
   public static void main (String [] args)  { 
       System.out.println ("hello"); 
    } 
} 
D.  //in file main.java 

class anothermain{ 
   public static void main (String [] args)  { 
       System.out.println ("hello2"); 
    } 
} 
class main  { 
   public final static void main (String [] args)  { 
       System.out.println ("hello"); 
    } 
} 


Correct Option is  : D

Note

Observe that the given code does not follow the standard Java naming convention.

The class names should start with a capital letter.

There are questions in the exam that contain similar non-conventional and confusing names and that is why we have kept a few questions like that in this question bank.




PreviousNext

Related