Keyword

Result: 191 questions

which of the following will happen?

import java.util.Arrays;
import java.util.Comparator;
public class X {
  private int x;
  public X(int x) {
    this.x = x;
  }
  public String toString() {
    return Integer.toString(x);
  }
  public static void main(String[] args) {
    X[] array = new X[3];
    array[0] = new X(3);
    array[1] = new X(1);
    array[2] = new X(2);
    Arrays.sort(array, new Comparator() {
      public int compare(X x1, X x2) {
        return x2.x - x1.x;
      }
    });
    System.out.println(Arrays.toString(array));
  }
}
Quiz

What is correct syntax for main method of a java class?

Quiz

which two statements, added independently at beginning of the program, allow the code to compile?

/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
    public static void main(String [] args) 
    {
        java.util.TreeSet t = new java.util.TreeSet();
        t.clear();
    }
    public void clear() 
    {
        TreeMap m = new TreeMap();
        m.clear();
    }
}
  1. No statement is required
  2. import java.util.*;
  3. import.java.util.Tree*;
  4. import java.util.TreeSet;
  5. import java.util.TreeMap;
Quiz

Which is a reserved word in the Java programming language?

Quiz

What will be the output of the program, if this code is executed with the command line:

java F0091 world

public class F0091 
{    
    public void main( String[] args ) 
    {  
        System.out.println( "Hello" + args[0] ); 
    } 
}

 

Quiz

What will be the output of the program?

public class CommandArgsTwo 
{
    public static void main(String [] argh) 
    {
        int x;
        x = argh.length;
        for (int y = 1; y <= x; y++) 
        {
            System.out.print(" " + argh[y]);
        }
    }
}

and the command-line invocation is

java CommandArgsTwo 1 2 3

Quiz

Which statement is true for the class java.util.ArrayList?

Quiz

What will be the output of the program?

public class Test138 
{ 
    public static void stringReplace (String text) 
    {
        text = text.replace ('j' , 'c'); /* Line 5 */
    } 
    public static void bufferReplace (StringBuffer text) 
    { 
        text = text.append ("c");  /* Line 9 */
    } 
    public static void main (String args[]) 
    { 
        String textString = new String ("java"); 
        StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */
        stringReplace(textString); 
        bufferReplace(textBuffer); 
        System.out.println (textString + textBuffer); 
    } 
}
Quiz

which two statements, added independently at beginning of the program, allow the code to compile?

  1. No statement is required
  2. import java.util.*;
  3. import.java.util.Tree*;
  4. import java.util.TreeSet;
  5. import java.util.TreeMap;
/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
    public static void main(String [] args) 
    {
        java.util.TreeSet t = new java.util.TreeSet();
        t.clear();
    }
    public void clear() 
    {
        TreeMap m = new TreeMap();
        m.clear();
    }
}
Quiz

which three statements are true?

  1. f1 == f2
  2. f1 == f3
  3. f2 == f1[1]
  4. x == f1[0]
  5. f == f1[0]
import java.awt.Button;
class CompareReference 
{
    public static void main(String [] args) 
    {
        float f = 42.0f;
        float [] f1 = new float[2];
        float [] f2 = new float[2];
        float [] f3 = f1;
        long x = 42;
        f1[0] = 42.0f;
    }
}
Quiz

What line of code should replace the missing statement to make this program compile?

/* Missing Statement ? */
public class foo 
{
    public static void main(String[]args)throws Exception 
    {
        java.io.PrintWriter out = new java.io.PrintWriter(); 
        new java.io.OutputStreamWriter(System.out,true); 
        out.println("Hello"); 
    } 
}
Quiz

which two of the following statements, inserted independently, could legally be inserted into missing section of this code?

  1. boolean test = (Component instanceof t);
  2. boolean test = (t instanceof Ticker);
  3. boolean test = t.instanceof(Ticker);
  4. boolean test = (t instanceof Component);
import java.awt.*;
class Ticker extends Component 
{
    public static void main (String [] args) 
    {
        Ticker t = new Ticker();
        /* Missing Statements ? */
    }
}
Quiz

and given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?

import java.io.*;
public class MyProgram 
{
    public static void main(String args[])
    {
        FileOutputStream out = null;
        try 
        {
            out = new FileOutputStream("test.txt");
            out.write(122);
        }
        catch(IOException io) 
        {
            System.out.println("IO Error.");
        }
        finally 
        {
            out.close();
        }
    }
}
Quiz

What will be the output of the program?

import java.util.*; 
class H 
{
    public static void main (String[] args) 
    { 
        Object x = new Vector().elements(); 
        System.out.print((x instanceof Enumeration)+","); 
        System.out.print((x instanceof Iterator)+","); 
        System.out.print(x instanceof ListIterator); 
    } 
}
Quiz

Which of the following are Java reserved words?

  1. run
  2. import
  3. default
  4. implement
Quiz

What will be the output of the program?

public class Test 
{ 
    public static void main (String[] args) 
    {
        String foo = args[1]; 
        String bar = args[2]; 
        String baz = args[3]; 
        System.out.println("baz = " + baz); /* Line 8 */
    } 
}

And the command line invocation:

java Test red green blue

Quiz

Which statement is true about assertions in the Java programming language?

Quiz

Which two can be used to create a new Thread?

  1. Extend java.lang.Thread and override the run() method.
  2. Extend java.lang.Runnable and override the start() method.
  3. Implement java.lang.Thread and implement the run() method.
  4. Implement java.lang.Runnable and implement the run() method.
  5. Implement java.lang.Thread and implement the start() method.
Quiz

What will be the output of the program?

import java.util.*;
public class NewTreeSet2 extends NewTreeSet 
{
    public static void main(String [] args) 
    {
        NewTreeSet2 t = new NewTreeSet2();
        t.count();
    }
}
protected class NewTreeSet
{
    void count() 
    {
        for (int x = 0; x < 7; x++,x++ ) 
        {
            System.out.print(" " + x);
        }
    }
}
Quiz

Which two statements are true for any concrete class implementing the java.lang.Runnable interface?

  1. You can extend the Runnable interface as long as you override the public run() method.
  2. The class must contain a method called run() from which all code for that thread will be initiated.
  3. The class must contain an empty public void method named run().
  4. The class must contain a public void method named runnable().
  5. The class definition must include the words implements Threads and contain a method called run().
  6. The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.
Quiz

© 2017 QuizBucket.org