JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
62

Consider the following two classes defined in two .java files.

//in file /root/com/foo/X.java

package com.foo;
public class X{
public static int LOGICID = 10;
public void apply(int i){
System.out.println("applied");
}
}

//in file /root/com/bar/Y.java

package com.bar;
//1 <== INSERT STATEMENT(s) HERE
public class Y{
public static void main(String[] args){
System.out.println(X.LOGICID);
}
}

What should be inserted at //1 so that Y.java can compile without any error?

Select 1 option

A. import static X;
B. import static com.foo.*;
C. import static com.foo.X.*;
D. import com.foo.*;
E. import com.foo.X.LOGICID;

Multiple Choice Question

QID: 
63

The following are the complete contents of TestClass.java file. Which packages are automatically imported?

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

Select 2 options

A. java.util
B. System
C. java.lang
D. java.io
E. String
F. The package with no name.

Multiple Choice Question

QID: 
64

Consider the following two java files:

//in file SM.java 

package x.y; 
public class SM{    
public static void foo(){ }; } 

//in file TestClass.java 

//insert import statement here //1 
public class TestClass{  
public static void main(String[] args){      
foo();   
} 
}

What should be inserted at //1 so that TestClass will compile and run?

Select 2 options 

A. import static x.y.*; 
B. import static x.y.SM; 
C. import static x.y.SM.foo; 
D. import static x.y.SM.foo(); 
E. import static x.y.SM.*;

Multiple Choice Question

QID: 
65

Which line(s) in the following code will cause a compilation error?

static import java.lang.System.*; //1
class $$ //2
{
static public void main(String... _$_) //3
{
String _ = ""; //4
for(int $=0; ++$ < _$_.length; ) //5
_ += _$_[$]; //6
out.println(_); //7
}
}

Select 1 option

A. 1
B. 2
C. 3
D. 4
E. 5
F. 6
G. 7
H. None of the lines is invalid.

Multiple Choice Question

QID: 
66

Consider the following code appearing in a file named TestClass.java:

class Test{ }  // 1
public class TestClass {
   public int main(String[] args)  { // 2
       double x=10, double y;  // 3
       System.out.println[]; // 4
       
        for(int k =0; k<x; k++){ } 
        
       return 0;
   }
}

Which of the lines are invalid?

Select 1 option

A. // 1 and // 4
B. // 3 and // 4 
C. // 2 and // 4 
D. // 2 and // 3

Pages

Search the Web

Custom Search

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