0

Instant Quiz Results

Instant Quiz Results

# of questions you got right:

The questions you got wrong:

Your Score in percentage:

0

Quiz

JavaScriptKit.com Multiple Choice Quiz Script

Test Your Skill in Java Part I


1) Consider

public class MyClass{
public MyClass(){/*code*/}
// more code...
}

To instantiate MyClass, you would write?
a) MyClass mc = new MyClass();
b) MyClass mc = MyClass();
c) MyClass mc = MyClass;
d) MyClass mc = new MyClass;

2) What gets printed when the following program is compiled and run?

class test
{
 public static void main(String args[])
  {
   int i;
   do
   {
    i++;
   }
   while(i < 0);
   System.out.println(i);
  }
}
a) The program does not compile as i is not initialized
b) The program compiles but does not run.
c) The program compiles and runs but does not print anything.
d) The program prints 0.

3) What is the result of compiling and running the following program.

public class test
{
  public static void main(String args[])
  {
   String str1="abc";
   String str2="def";
   String str3=str1.concat(str2);
   str1.concat(str2);
   System.out.println(str1);
  }
}
a) abc
b) def
c) abcabc
d) abcdef

4) What gets printed when the following code is compiled and run.

public class test
{
  public static void main(String args[])
  {
   int i = 1;
   do
   {
   i--;
   }
   while (i > 2);
   System.out.println(i);
  }
}
a) 0
b) 1
c) 2
d) -1

5) How can you ensure that the memory allocated by an object is freed ?
a) By invoking the free method on the object.
b) By calling system.gc() method.
c) By setting all references to the object to new values (say null).
d) Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.

6) Which of the following statements are true
a) Arrays in Java are essentially objects.
b) It is not possible to assign one array to another. Individual elements of array can however be assigned.
c) Array elements are indexed from 1 to size of array.
d) If a method tries to access an array element beyond its range, a compile warning is generated.

7) What is garbage collection in the context of Java?
a) The operating system periodically deletes all of the java files available on the system.
b) Any package imported in a program and not used is automatically deleted.
c) When all references to an object are gone, the memory used by the object is automatically reclaimed.
d) The JVM checks the output of any Java program and deletes anything that doesn't make sense.

8) What gets printed when the following code is compiled and run.

public class test
{
  public static void main(String args[])
  {
   int i=0, j=2;
   do
   {
    i=++i;
    j--;
   } while(j>0);
   System.out.println(i);
  }
}
a) 0
b) 1
c) 2
d) The program does not compile because of statement "i=++i;"

9) What gets printed when the following code is compiled and run with the following command -
java test 2

public class test
{
  public static void main(String args[])
  {
   Integer intObj=Integer.valueOf(args[args.length-1]);
   int i = intObj.intValue();

   if(args.length > 1)
    System.out.println(i);
   if(args.length > 0)
    System.out.println(i - 1);
   else
    System.out.println(i - 2);
  }
}
a) test
b) test-1
c) 0
d) 1

10) Which of the following is TRUE?
a) In java, an instance field declared public generates a compilation error.
b) int is the name of a class available in the package java.lang
c) Instance variable names may only contain letters and digits.
d) A class has always a constructor (possibly automatically supplied by the java compiler).

 
My WordPress Hi! You can put anything here, be sure not exceed the limit.