Witscale Test Center

Sample test


Sample test

1.    Which of the following are valid signatures for the main method acting as an entry point for a java application?

 

A.    static public int main(String args[])

B.    public static void main(String numbers[])

C.    static void public main(String args)

D.    static public void main(String args)

E.    public static void main()

F.    public static void main(String args)[]

G.    public void main(String [] args)

 

2.    Consider the given code. Which of the following statements are true about it? (Choose all the correct answers)

 

                                1.            // This is a source file

                                2.             

                                3.            import java.io.*;

                                4.            import java.util.*;

                                5.             

                                6.            package com.example.fundamentals;

                                7.             

                                8.            class HelloWorld{

                                9.             

                             10.             public static void main(String[] args) {

                             11.              System.out.println("Hello World!");

                             12.             }

                             13.            }

                             14.             

                             15.            public class Test {

                             16.              void test() {

                             17.              }

                             18.            }

 

 

A.      The code will fail to compile because the main method in the class HelloWorld is not legal.

B.      The code will fail to compile because the public top-level class Test must be defined before the class HelloWorld.

C.      The code will not compile as it is, but if you remove the comment on line 1, it will compile successfully.

D.     The code will not compile as it is, but if you remove the package declaration at line 6, it will compile successfully.

E.      The code will fail to compile because the public top-level class Test does not have a main method.

F.       The code will fail to compile because none of the top-level classes are making use of imported classes.

 

 

3.    Consider the given code. What is the result if you run the application as-

 

$ java  ThreeBlindMice Frisky Mickey Longtail

 

 

               1. public class ThreeBlindMice implements Runnable {

               2.        

               3.       public void run() {

               4.        }

               5.       public static void main(String[] args) {

               6.         String mouse1 = args[1];

               7.         String mouse2 = args[2];

               8.         String mouse3 = args[3];

               9.         System.out.print("Name of second mouse is " + mouse2);

           10.     }

           11. }

 

A.      This code will not compile as the interface Runnable is not implemented properly.

B.      This code will fail to compile, as the run method is empty.

C.    Name of second mouse is Frisky

D.    Name of second mouse is Longtail

E.    Name of second mouse is Mickey

F.       This code will compile but throw runtime exception (ArrayIndexOutOfBoundsException) at line 8.

 

 

4.    Which three of the following statement are false about the default values for the declared member variables?

 

A.      The default value for variable of String type is “”

B.      The default value for variable of boolean type is true

C.      The default value for variable of int type is 0

D.     The default value for variable of float type is 0.0

E.      The default value for variable of double type is 0.0

F.       The default value for variable of java.util.Vector type is null.

 

5.    Consider the given code. What will happen if you try to compile and run it?

 

               1.  package com.example.fundamentals;

               2.  import java.util.Date;

               3.   public class MortgageApplication {

               4.     String name;

               5.     float interestRate;

               6.     int age;

               7.     boolean eligible;

               8.     char sex;

               9.     private float getInterestRate() {

           10.         Date applicationDate;

           11.         if (applicationDate == null) {

           12.           applicationDate = new Date();

           13.         }

           14.         if (age >= 18) {

           15.           interestRate = 9.0f;

           16.         }

           17.         return interestRate;

           18.     }

           19.  

           20.     public static void main(String[] args) {

           21.       MortgageApplication app = new MortgageApplication();

           22.       System.out.println("Interest rate = " + app.getInterestRate());

           23.     }

           24.   }

 

 

A.      Interest rate = 0.0 is printed

B.      Interest rate = 9.0 is printed

C.      The code fails to compile at line 22 as getInterestRate() is a private method of MortgageApplication.

D.     The code fails to compile at line 10 as applicationDate is not initialized.

E.      The code fails to compile at line 11 as applicationDate is not initialized.

F.       The code fails to compile at line 14 as age is not initialized.

 

 

6.    Which of the following class declarations properly implement the java.lang.Runnable interface?

 

A.      class MyThread extends Runnable { public void run();}

B.      class MyThread implements Runnable {}

C.      class MyThread implements Runnable { public void run() {return null;} }

D.     class MyThread implements Runnable { public boolean run() { return true;} }

E.      class MyThread extends Object, Runnable { public void run();}

F.       abstract class MyThread implements Runnable {}

G.     None of the above

 

 

7.    Consider the following method.

 

               4. public int multiply(int a, int b) {

               5.   int result; 

               6.   result = a * b;

               7.   System.out.println(a + “ ” + b + “ ” + result);

               8.   return result;               

               9. }

 

Which of the following statements are true about this method?

 

A.      The method fails to compile at line 5 as result is not initialized.

B.      The method fails to compile at line 7 as a, b and result are not initialized.

C.      The method fails to compile at line 8 as result is not initialized.

D.     The method fails to compile at line 7 as a and b are not initialized.

E.      This method compiles successfully.

 

 

8.    Consider the following method.

 

               4. public int divide(int a, int b) {

               5.   int result; 

               6.   if (b != 0)

               7.     result = a / b;

               8.   else

               9.     result = b;

           10.   System.out.println(a + “ ” + b + “ ” + result);           

           11.   return result;               

           12.  }

 

Which of the following statements are true about this method?

 

A.      The method fails to compile at line 5 as result is not initialized.

B.      The method fails to compile at line 10 as a, b and result are not initialized.

C.      The method fails to compile at line 10 as result is not initialized.

D.     The method fails to compile at line 11 as result is not initialized.

E.      This method compiles successfully.