JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
57

Which of the following lines can be inserted at line 1 to make the program run?

//line 1
public class TestClass{
public static void main(String[] args){
PrintWriter pw = new PrintWriter(System.out);
OutputStreamWriter osw = new OutputStreamWriter(System.out
);
pw.print("hello");
}
}

Assume that PrintWriter and OutputStreamWriter are valid classes in java.io package. 

Select 1 option

A. import java.lang.*;
B. import java.io.*;
C. import java.io.OutputStreamWriter;
D. include java.io.*;
E. include java.lang.System;

Multiple Choice Question

QID: 
58

Given the following contents of two java source files:

package util.log4j;
public class Logger {
public void log(String msg){
System.out.println(msg);
}
}

and

package util;
public class TestClass {
public static void main(String[] args) throws Exception {
Logger logger = new Logger();
logger.log("hello");
}
}

What changes, when made independently, will enable the code to compile and run?

Select 2 options
A. Replace Logger logger = new Logger(); with:
         log4j.Logger logger = new log4j.Logger();
B. Replace package util.log4j; with
         package util;
C. Replace Logger logger = new Logger(); with:
          util.log4j.Logger logger = new util.log4j.Logger();
D. Remove package util.log4j; from Logger.
E. Add import log4j; to TestClass.

Multiple Choice Question

QID: 
59

Which of the following are not legal Java identifiers?

Select 1 option

A. goto
B. unsigned
C. String
D. _xyz
E. $_abc
F. iLikeVeryVeryVeryVeryVeryLongIdentifiersThatDontMakeAnySenseAtAll (65 characters)

Multiple Choice Question

QID: 
60

What will the following code print when run?

public class TestClass{
  public static long main(String[] args){
     System.out.println("Hello");
     return 10L;
  }
}

Select 1 option

A. Hello
B. It will print nothing.
C. It will not compile
D. It will throw a Throwable at runtime.
E. None of the above.

Multiple Choice Question

QID: 
61

Consider the following 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 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 2 options

A. import com.enthu.*;
B. import com.*.*;
C. import *.*.*;
D. import com.*;
E. import com.enthu.rad.*;
F. import all;

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!