283). What will be the output of the following Java snippet, if attempted to compile and run this code with command line argument “java abc Rakesh Sharma”?
public class abc
{
	int a=2000;
        public static void main(String argv[])
        {
	    System.out.println(argv[1]+" :-Please pay Rs."+a);
        }
}

[A]Compile time error
[B]Compilation but runtime error
[C]Compilation and output Rakesh :-Please pay Rs.2000
[D]Compilation and output Sharma :-Please pay Rs.2000

Show Answer

284). What will be the output of the following Java snippet, if attempted to compile and execute?
class abc
{
    public static void main(String args[])
    {
        if(args.length>0)
        System.out.println(args.length);
    }
}

[A]The snippet compiles, runs and prints 0
[B]The snippet compiles, runs and prints 1
[C] The snippet does not compile
[D]The snippet compiles and runs but does not print anything

Show Answer

285). What will be the output of the following Java snippet, if compiled and executed with command line argument “java abc 1 2 3”?
public class abc
{
   static public void main(String [] xyz)
   {
       for(int n=1;n

[A]1 2
[B]2 3
[C]1 2 3
[D]Compilation error

Show Answer

286). What will be the output of the following Java code snippet running with “java demo I write java code”?
public class demo
{
   public static void main(String args[])
   {
        System.out.println(args[0]+""+args[args.length-1]);
   }
}

[A]The snippet compiles, runs and prints “java demo”
[B]The snippet compiles, runs and prints “java code”
[C]The snippet compiles, runs and prints “demo code”
[D]The snippet compiles, runs and prints “I code”

Show Answer

287). What will be the output of the following Java snippet, if compiled and executed with command line “hello there”?
public class abc
{
    String[] xyz;
 
    public static void main(String argv[])
    {
        xyz=argv;
    }
 
    public void runMethod()
    {
        System.out.println(argv[1]);
    }
}

[A]Compile time error
[B]Output would be “hello”
[C]Output would be “there”
[D]Output would be “hello there”

Show Answer

288). How do we pass command line argument in Eclipse?
public class abc
{
    String[] xyz;
 
    public static void main(String argv[])
    {
        xyz=argv;
    }
 
    public void runMethod()
    {
        System.out.println(argv[1]);
    }
}

[A]Arguments tab
[B]Variable tab
[C]Cannot pass command line argument in eclipse
[D]Environment variable tab

Show Answer

289). Which class allows parsing of command line arguments?
public class abc
{
    String[] xyz;
 
    public static void main(String argv[])
    {
        xyz=argv;
    }
 
    public void runMethod()
    {
        System.out.println(argv[1]);
    }
}

[A]Args
[B]JCommander
[C]Command Line
[D]Input

Show Answer

290). Which annotation is used to represent command line input and assigned to correct data type?
public class abc
{
    String[] xyz;
 
    public static void main(String argv[])
    {
        xyz=argv;
    }
 
    public void runMethod()
    {
        System.out.println(argv[1]);
    }
}

[A]@Input
[B] @Variable
[C]@Command Line
[D] @Parameter

Show Answer

291). What will be the output of the following Java code snippet run as $ java Demo –length 512 –breadth 2 -h 3?
class Demo {
    @Parameter(names={"--length"})
    int length;
 
    @Parameter(names={"--breadth"})
    int breadth;
 
    @Parameter(names={"--height","-h"})
    int height;
 
    public static void main(String args[]) 
    {
        Demo demo = new Demo();
        new JCommander(demo, args);
        demo.run();
    }
 
    public void run() 
    {
        System.out.println(length+" "+ breadth+" "+height);
    }
}

[A]2 512 3
[B]2 2 3
[C]512 2 3
[D]512 512 3

Show Answer

292). What is the use of @syntax?
class Demo {
    @Parameter(names={"--length"})
    int length;
 
    @Parameter(names={"--breadth"})
    int breadth;
 
    @Parameter(names={"--height","-h"})
    int height;
 
    public static void main(String args[]) 
    {
        Demo demo = new Demo();
        new JCommander(demo, args);
        demo.run();
    }
 
    public void run() 
    {
        System.out.println(length+" "+ breadth+" "+height);
    }
}

[A]Allows multiple parameters to be passed
[B]Allows one to put all your options into a file and pass this file as a parameter
[C]Allows one to pass only one parameter
[D]Allows one to pass one file containing only one parameter

Show Answer