Java Programming Fundamentals

Test your knowledge of Java language syntax, array declarations, abstract classes, interfaces, and object-oriented programming concepts.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What are the two parts of a value of type double?

  1. significant digits
  2. length
  3. numerator
  4. denominator
Question 2 Multiple Choice (Single Answer)

After the following code fragment, what is the value in a?String s;int a;s = "Foolish boy.";a = s.indexOf("fool");

  1. -1
  2. 0
  3. 4
  4. 8
Question 3 Multiple Choice (Single Answer)

What is the value of k after the following code fragment? int k = 0; int n = 12 while (k < n) { k = k + 1; }

  1. O
  2. 11
  3. 12
  4. -3
Question 4 Multiple Choice (Single Answer)

Given the following code fragment:int A[];int i = 0;A = new int A[4];while (i < 4){A[i] = 10;i = i + 1;}

  1. 0
  2. 3
  3. 10
  4. UNKNOWN
Question 5 Multiple Choice (Single Answer)

Given the following statement:huey.setDouble(8.0*32.2+1.0);What must be the data type of huey?

  1. DoubleField
  2. TextField
  3. IntField
  4. double
Question 6 Multiple Choice (Single Answer)

The method setLabel can be used with what type of Object?

  1. DoubleField
  2. int
  3. TextField
  4. String
Question 7 Multiple Choice (Single Answer)

A function is:

  1. An entity that receives inputs and outputs
  2. A way of storing values
  3. A sequence of characters enclosed by quotes
  4. A kind of computer
Question 8 True/False

A signed data type has an equal number of non-zero positive and negative values available.TRUE/FALSE ?

  1. True
  2. False
Question 9 Multiple Choice (Single Answer)

class C1 { static interface I { static class C2 { } } public static void main(String a[]) { C1.I.C2 ob1=new C1.I.C2(); System.out.println("object created"); } } What is the result of attempting to compile and run the program?

  1. prints object created
  2. Compile time error
  3. Runtime Excepion
  4. None of the above
Question 10 Multiple Choice (Single Answer)

class C1 { static class C2 { static int i1; } public static void main(String a[]) { System.out.println(C1.C2.i1); } } What is the result of attempting to compile and run the program?

  1. prints 0
  2. Compile time error
  3. Runtime exception
  4. None of the above
Question 11 Multiple Choice (Multiple Answers)

Which declare a compilable abstract class? (Choose all that apply.)

  1. A. public abstract class Canine { public Bark speak(); }
  2. B. public abstract class Canine { public Bark speak() { } }
  3. C. public class Canine { public abstract Bark speak(); }
  4. D. public class Canine abstract { public abstract Bark speak(); }
Question 12 Multiple Choice (Multiple Answers)

Which are legal declarations?

  1. short x [];
  2. short [] y;
  3. short [5] x2;
  4. short z2 [5];
  5. short [] z [] [];
  6. short [] y2 = [5];
Question 13 Multiple Choice (Multiple Answers)

Which is true? (Choose all that apply. )

  1. A. "X extends Y" is correct if and only if X is a class and Y is an interface
  2. B. "X extends Y" is correct if and only if X is an interface and Y is a class
  3. C. "X extends Y" is correct if X and Y are either both classes or both interfaces
  4. D. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces
Question 14 Multiple Choice (Multiple Answers)

Given: 1. class Voop { 2. public static void main(String [] args) { 3. doStuff(1); 4. doStuff(1, 2); 5. } 6. // insert code here 7. } Which, inserted independently at line 6, will compile? (Choose all that apply.)

  1. static void doStuff(int... doArgs) { }
  2. static void doStuff (int [] doArgs) { }
  3. static void doStuff(int doArgs...) { }
  4. static void doStuff(int... doArgs, int y) { }
  5. static void doStuff(int x, int... doArgs) { }
Question 15 Multiple Choice (Multiple Answers)

Given the following, 1. interface Base { 2. boolean m1 (); 3. byte m2(short s); 4. } Which code fragments will compile? (Choose all that apply.)

  1. interface Base2 implements Base { }
  2. abstract class Class2 extends Base { public boolean ml() { return true; } }
  3. abstract class Class2 implements Base { }
  4. abstract class Class2. implements Base { public boolean m1() { return (true); } }
  5. class Class2 implements Base { boolean m1( ) { return false; } byte m2(short s) { return 42; } }
Question 16 Multiple Choice (Multiple Answers)

Which declare a compilable abstract class? (Choose all that apply.)

  1. public abstract class Canine { public Bark speak(); }
  2. public abstract class Canine { public Bark speak() { } }
  3. public class Canine { public abstract Bark speak(); }
  4. public class Canine abstract { public abstract Bark speak(); }
Question 17 Multiple Choice (Multiple Answers)

Which is true? (Choose all that apply. )

  1. "X extends Y" is correct if and only if X is a class and Y is an interface.
  2. "X extends Y" is correct if and only if X is an interface and Y is a class.
  3. "X extends Y" is correct if X and Y are either both classes or both interfaces.
  4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
Question 18 Multiple Choice (Multiple Answers)

Given: 1. class Voop { 2. public static void main(String [] args) { 3. doStuff(1); 4. doStuff(1, 2); 5. } 6. // insert code here 7. } Which, inserted independently at line 6, will compile? (Choose all that apply.)

  1. static void doStuff(int... doArgs) { }
  2. static void doStuff (int [] doArgs) { }
  3. static void doStuff(int doArgs...) { }
  4. static void doStuff(int... doArgs, int y) { }
  5. static void doStuff(int x, int... doArgs) { }
Question 19 Multiple Choice (Multiple Answers)

Which are legal declarations? (Choose all that apply. )

  1. short x [];
  2. short [] y;
  3. short [5] x2;
  4. short z2 [5];
  5. short [] z [] [];
  6. short [] y2 = [5];
Question 20 Multiple Choice (Single Answer)

Can there be multiple tag in tiles-defs.xml?

  1. No
  2. Yes
  3. always present
  4. None of the above