Java Basic

Quiz Guidelines

 

Multiple Choice Question

QID: 
67

Which of the following is/are illegal Java identifier(s)?

Select 1 option

A. num
B. int123
C. 2Next
D. _interface
E. a$_123

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

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: 
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: 
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.

Pages