Java Basic

Quiz Guidelines

 

Multiple Choice Question

QID: 
72

Which of the given options should be inserted at line 1 so that the following code can compile without any errors?

package objective1;       // 1
public class StaticImports{
public StaticImports(){
out.println(MAX_VALUE);
}
}

(Assume that java.lang.Integer has a static field named MAX_VALUE)

Select 2 options

A. import static java.lang.Integer.*;
B. static import java.lang.System.out;
C. static import Integer.MAX_VALUE;
D. import static java.lang.System.*;
E. static import java.lang.System.*;

Multiple Choice Question

QID: 
71

Consider the directory structure shown in Image 1 that displays available folders and classes and the code is given below:

class StockQuote{  
Stock stock;  
public StockQuote(Stock s)  {  }  
public void store() throws IOException{    
return Util.store(stock);  }  
public double computePrice(){    
return Helper.getPricer(stock).price(); 
 } }

Assuming that the code uses valid method calls, what statements MUST be added to the above class?

Select 4 options

A. package com.enthu.rad.*; 
B. import com.enthu.*; 
C. package com.enthu.rad; 
D. import com.*; 
E. import java.io.*; 
F. It is not required to import java.io.* or import java.io.IOException because java.io package is imported automatically. 

Multiple Choice Question

QID: 
70

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 {
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");
}
}

Multiple Choice Question

QID: 
69

What is the correct parameter specification for the standard main method?

Select 2 options

A. void
B. String[ ] args
C. Strings args[ ]
D. String args
E. String args[ ]

Multiple Choice Question

QID: 
68

Which of the following are valid declarations:

Select 3 options

A. int a = b = c = 100;
B. int a, b, c; a = b = c = 100;
C. int a, b, c=100;
D. int a=100, b, c;
E. int a= 100 = b = c;

Pages