logo

CuriousTab

CuriousTab

Language Fundamentals problems


  • 1. Which four options describe the correct default values for array elements of the types indicated?

    1. int -> 0
    2. String -> "null"
    3. Dog -> null
    4. char -> '\u0000'
    5. float -> 0.0f
    6. boolean -> true

  • Options
  • A. 1, 2, 3, 4
  • B. 1, 3, 4, 5
  • C. 2, 4, 5, 6
  • D. 3, 4, 5, 6
  • Discuss
  • 2. Which one of these lists contains only Java programming language keywords?

  • Options
  • A. class, if, void, long, Int, continue
  • B. goto, instanceof, native, finally, default, throws
  • C. try, virtual, throw, final, volatile, transient
  • D. strictfp, constant, super, implements, do
  • E. byte, break, assert, switch, include
  • Discuss
  • 3. Which three are legal array declarations?

    1. int [] myScores [];
    2. char [] myChars;
    3. int [6] myScores;
    4. Dog myDogs [];
    5. Dog myDogs [7];

  • Options
  • A. 1, 2, 4
  • B. 2, 4, 5
  • C. 2, 3, 4
  • D. All are correct.
  • Discuss
  • 4. Which will legally declare, construct, and initialize an array?

  • Options
  • A. int [] myList = {"1", "2", "3"};
  • B. int [] myList = (5, 8, 2);
  • C. int myList [] [] = {4,9,7,0};
  • D. int myList [] = {4, 3, 7};
  • Discuss
  • 5. What will be the output of the program?
    public class CommandArgsThree 
    {
        public static void main(String [] args) 
        {
            String [][] argCopy = new String[2][2];
            int x;
            argCopy[0] = args;
            x = argCopy[0].length;
            for (int y = 0; y < x; y++) 
            {
                System.out.print(" " + argCopy[0][y]);
            }
        }
    }
    
    and the command-line invocation is

    > java CommandArgsThree 1 2 3


  • Options
  • A. 0 0
  • B. 1 2
  • C. 0 0 0
  • D. 1 2 3
  • Discuss
  • 6. What will be the output of the program?
    public class X 
    {
        public static void main(String [] args) 
        {
            String names [] = new String[5];
            for (int x=0; x < args.length; x++)
                names[x] = args[x];
            System.out.println(names[2]);
        }
    }
    
    and the command line invocation is

    > java X a b


  • Options
  • A. names
  • B. null
  • C. Compilation fails
  • D. An exception is thrown at runtime
  • Discuss
  • 7. 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] ); 
        } 
    }
    

  • Options
  • A. Hello
  • B. Hello Foo91
  • C. Hello world
  • D. The code does not run.
  • Discuss
  • 8. 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


  • Options
  • A. 0 1 2
  • B. 1 2 3
  • C. 0 0 0
  • D. An exception is thrown at runtime
  • Discuss
  • 9. What will be the output of the program?
    public class TestDogs 
    {
        public static void main(String [] args) 
        {
            Dog [][] theDogs = new Dog[3][];
            System.out.println(theDogs[2][0].toString());
        }
    }
    class Dog { }
    

  • Options
  • A. null
  • B. theDogs
  • C. Compilation fails
  • D. An exception is thrown at runtime
  • Discuss
  • 10. What will be the output of the program?
    public class Test 
    {
        public static void main(String [] args) 
        {
            signed int x = 10;
            for (int y=0; y<5; y++, x--)
                System.out.print(x + ", ");
        }
    }
    

  • Options
  • A. 10, 9, 8, 7, 6,
  • B. 9, 8, 7, 6, 5,
  • C. Compilation fails.
  • D. An exception is thrown at runtime.
  • Discuss

First 2 3