Java Programming Fundamentals

Test your knowledge of Java programming language fundamentals including syntax, keywords, object-oriented concepts, and language features.

16 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

Which modifier is used to prevent a method from being overridden?

  1. 1. final
  2. 2. native
  3. 3. local
  4. 4. protected
Question 2 Multiple Choice (Multiple Answers)

You have the following class definitions: public abstract class Vehicles { } public class Bus { } public class MyClass { public Vehicles go() { return new Bus(); } } What change would have to be made to allow this code to compile?

  1. 1. Change public abstract class Vehicles { } to public class Vehicles { }
  2. 2. Change public class Bus { } to public class Bus extends Vehicles { }
  3. 3. Change public class MyClass { to private class My Class {
  4. 4. Change public abstract class Vehicles { } to protected abstract class Vehicles { }
Question 3 Multiple Choice (Multiple Answers)

. Which line of the following code would make the test object eligible for garbage collection? (Line numbers are included only for clarity's sake) 1. public class Garbage { 2. public static void main(String [] args) { 3. StringBuffer test = new StringBuffer("hello"); 4. System.out.println(test); 5. test = null; 6. } 7. }

  1. 1. 3
  2. 2. 4
  3. 3. 5
  4. 4. No lines enable the garbage collection of the test object.
Question 4 Multiple Choice (Multiple Answers)

21Which statement is correct concerning the assertion mechanism?

  1. 1 This is the pseudocode representing the two types of assert statements:
  2. 2 Always handle an AssertionError in a try-catch-finally block.
  3. 3 This is the pseudocode representing the two types of assert statements:
  4. 4 Assertions of the 'assert booleanExpression;' variety should not be disabled before distributing the software.
Question 5 Multiple Choice (Multiple Answers)

which option is a declaration of an array of Strings, called sSyntax, containing 50 elements shared between instances of a class? Incorrect. The correct option is as follows

  1. 1. static String [50] sSyntax = new String[];
  2. 2. String [] sSyntax = new String[50];
  3. 3. static String [] sSyntax = new String[50];
  4. 4. static string [] sSyntax = new string[50];
Question 6 Multiple Choice (Multiple Answers)

You have the following class definition: public class Language {} You need constructors to provide developers with two methods of object instantiation. Developers should be able to instantiate the object with either a String argument or no argument. What should you do to achieve this goal? (Choose all that apply.) You have not made any correct choices. The correct options are as follows

  1. 1. Add Language (string Name) {}
  2. 2. Add Language ( ) { }
  3. 3. Add Language (String Name) { }
  4. 4. Allow the compiler to add a default constructor.
Question 7 Multiple Choice (Multiple Answers)

Why will the following code not compile? Boolean b = new Boolean("false"); if (b) {}

  1. 1. The quotes should not be around false.
  2. 2. New should be after Boolean.
  3. 3. A boolean is expected not a Boolean.
  4. 4. The Semi-colon should not be used.
Question 8 Multiple Choice (Multiple Answers)

You have the following code: public class Java { public static void main (String [] args) { double dSyntaxs; System.out.println("Its: " + dSyntaxs); } public void TrueSyntax() { System.out.println("True syntax is a work of art."); } } What would the output be? Incorrect. The correct option is as follows

  1. 1. Its: 1
  2. 2. Its: 0
  3. 3. Its: true
  4. 4. Its: 0.0
  5. 5. A compiler error
Question 9 Multiple Choice (Single Answer)

What is the output for the following expression = ceil {-4.5}

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

What is the output for the following expression = ceil {-4.5}

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

Java is developed by

  1. Dennis Ritchie
  2. Bjarne Stroustrup
  3. James Gosling
  4. Paul Allen
Question 12 Multiple Choice (Single Answer)

Java was intially called as

  1. green
  2. Oak
  3. bean
  4. applet
Question 13 Multiple Choice (Single Answer)

Which is not the scripting language

  1. Java Tcl
  2. JRuby
  3. Sleep
  4. JavaOne
Question 14 Multiple Choice (Single Answer)

Which is not the keyword

  1. java
  2. boolean
  3. super
  4. this
Question 15 Multiple Choice (Single Answer)

How do you write an infinite loop using the for statement

  1. while(true){ }
  2. for(i=0;i>1;i--){ i++ }
  3. for ( ; ; ) { }
  4. while(false){ }
Question 16 Multiple Choice (Multiple Answers)

What is the output of the following code when compiled and run? Select two correct answers. public class Question01 { public static void main(String[] args){ int y=0; //line 1 int x=z=1; //line 2 System.out.println(y+","+x+","+z); //line 3 } }

  1. Prints 0,1,1
  2. Error during compilation at line 1
  3. E. Error during compilation at line 2
  4. Error during compilation at line 3