Java Programming Fundamentals Quiz

Comprehensive quiz covering Java fundamentals including OOP concepts, exception handling, strings, arrays, loops, Swing GUI components, and basic syntax

40 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

String constructor cannot be passed

  1. char arrays
  2. int arrays
  3. byte arrays
  4. Strings
Question 2 Multiple Choice (Single Answer)

String objects are immutable. This means they

  1. must be initialized
  2. cannot be deleted
  3. cannot be changed
  4. None of the above
Question 3 Multiple Choice (Single Answer)

What class cannot be instantiated

  1. Final
  2. Concrete
  3. Abstract
  4. Polymorphic
Question 4 Multiple Choice (Single Answer)

Which class in Java does not extends an existing class

  1. Integer
  2. Object
  3. String
  4. Class
Question 5 Multiple Choice (Single Answer)

Composition is also known as the

  1. knows-a relationship
  2. has-a relationship
  3. uses-a relationship
  4. is-a relationship
Question 6 Multiple Choice (Single Answer)

Superclass methods with this level of access cannot be called from subclasses

  1. private
  2. public
  3. protected
  4. package
Question 7 Multiple Choice (Single Answer)

Which method changes the text the label displays?

  1. changeText
  2. setText
  3. ChangeLabel
  4. setLabel
Question 8 Multiple Choice (Single Answer)

Exceptions can be thrown by

  1. the Java Virtual Machine
  2. code in a try block
  3. calls from a try block to other methods
  4. All of the above
Question 9 Multiple Choice (Single Answer)

All exception classes inherit, either directly or indirectly from

  1. class Error
  2. class RuntimeException
  3. class Throwable
  4. None of the above
Question 10 Multiple Choice (Single Answer)

Which is not a GUI component?

  1. String
  2. Button
  3. Menu
  4. Combo box
Question 11 Multiple Choice (Single Answer)

What will be the output of the program?

  1. finished
  2. Exception
  3. Compilation fails.
  4. Arithmetic Exception
Question 12 Multiple Choice (Single Answer)

Which one create an anonymous inner class from within class Bar?

  1. Boo f = new Boo(24) { };
  2. Boo f = new Bar() { };
  3. Bar f = new Boo(String s) { };
  4. Boo f = new Boo.Bar(String s) { };
Question 13 Multiple Choice (Single Answer)

Which constructs an anonymous inner class instance?

  1. Runnable r = new Runnable() { };
  2. Runnable r = new Runnable(public void run() { });
  3. Runnable r = new Runnable { public void run(){}};
  4. System.out.println(new Runnable() {public void run() { }});
Question 14 Multiple Choice (Single Answer)

Which is true about an anonymous inner class?

  1. Extend exactly one class and implement exactly one interface
  2. Extend exactly one class and implement multiple interfaces
  3. Extend exactly one class or implement exactly one interface
  4. implement multiple interface
Question 15 Multiple Choice (Single Answer)

What are Wrapper classes?

  1. Classes that wraps functionality of an existing class.
  2. Classes that allow primitive types to be accessed as objects
  3. Both of the above.
  4. None of the above.
Question 16 Multiple Choice (Single Answer)

What is Abstraction?

  1. defines different methods of same type.
  2. the ability of an object to take on many forms.
  3. A summary of a Class.
  4. It refers to the ability to make a class abstract in OOP.
Question 17 Multiple Choice (Single Answer)

Besides Object all Exceptions and Errors are descended from what class?

  1. Extends
  2. Object
  3. Throwable
  4. Throws
Question 18 Multiple Choice (Single Answer)

What clause identifies a method as one that may throw an IOException or a WidgetException?

  1. throws IoException, WidgetException
  2. catch IOException, WidgetException
  3. throws Exception, WidgetException
  4. throws WidgetException. IOException
Question 19 Multiple Choice (Single Answer)

The method used to arrange for a button to notify another object when it is clicked later is?

  1. addMouseListener
  2. addListener
  3. addObjectListener
  4. addActionListener
Question 20 Multiple Choice (Single Answer)

What is the component that provides a box for writing one line of text in a GUI application?

  1. JTextField
  2. JMultiLineField
  3. JLabelField
  4. JTextArea
Question 21 Multiple Choice (Single Answer)

The import statement needed to use JOptionPane is

  1. import javax.Swing.JOptionPane ;
  2. import javax.swing.JOptionPane ;
  3. import java.swing.JOptionPane ;
  4. import javac.swing.JOptionPane ;
Question 22 Multiple Choice (Single Answer)

String s1 = "Hello", s2 = "Hi"; //Which code exchanges their values?

  1. String temp = s2; s2 = s1; s2 = temp;
  2. String s1 = temp; s1 = s2; s1 = temp;
  3. String temp = s1; s1 = s2; s2 = temp;
  4. String temp = s1; s1 = s2; s1 = temp;
Question 23 Multiple Choice (Single Answer)

Which expression is true if and only if x is NOT a upper-case letter. x is a char variable

  1. x<'A' && x >'Z'
  2. x<'a' || x >'z'
  3. x<'a' && x >'z'
  4. x<'A' || x >'Z'
Question 24 Multiple Choice (Single Answer)

Consider the code given, what is the output of the code above?

  1. 30
  2. Compiler Error
  3. Runtime Error
  4. Exception
Question 25 Multiple Choice (Single Answer)

In the main method of MyClassTester, how many objects of type MyClass are created?

  1. 1
  2. 2
  3. 3
  4. 4
Question 26 Multiple Choice (Single Answer)

Which keyword do you use to create a new instance of an object?

  1. this
  2. object
  3. new
  4. class
Question 27 Multiple Choice (Single Answer)

When is it OK to have an overloaded method that has a different return type?

  1. Only when the parameter list is also different
  2. Never
  3. Always
  4. At compilation time
Question 28 Multiple Choice (Single Answer)

for(int i = 0; i < 10; i++) How many times does "i<10" execute?

  1. 9 times
  2. 10 times
  3. 11 times
  4. compile time error
Question 29 Multiple Choice (Single Answer)

In Java, an array starts counting from...

  1. 0
  2. 2
  3. 1
  4. begin
Question 30 Multiple Choice (Single Answer)

An if statement can contain how many else if statements?

  1. Only two
  2. As many as you want
  3. None
  4. One
Question 31 Multiple Choice (Single Answer)

Which variable type would you use for a city name?

  1. int
  2. String
  3. double
  4. float
Question 32 Multiple Choice (Single Answer)

Which method prints text in a Java program?

  1. System.out()
  2. out.write.Text()
  3. System.out.println()
  4. System.printText()
Question 33 Multiple Choice (Single Answer)

Which method is the starting point for all Java programs?

  1. void
  2. public
  3. class
  4. main
Question 34 Multiple Choice (Single Answer)

Complete the statement: The JVM

  1. compiles source files into object files.
  2. compiles source files into machine code.
  3. translates bytecode into machine code.
  4. executes a java program and creates an executable file.
Question 35 Multiple Choice (Single Answer)

How are Java applications distributed?

  1. Using .java source files
  2. Using Java archive with .exe extension
  3. Using Java archive with .jar extension
  4. Using Java archive with .jvm extension
Question 36 Multiple Choice (Single Answer)

What is the extension for Java source code files?

  1. .cpp
  2. .java
  3. .c
  4. .jpp
Question 37 Multiple Choice (Single Answer)

What is the return type of the method?

  1. float
  2. double
  3. public
  4. int
Question 38 Multiple Choice (Single Answer)

To distribute your app to different platforms, how many Java version do you need to create?

  1. Two versions
  2. One for each platform
  3. Just one version
  4. Ask Prof. Itauma