Java Programming Fundamentals Quiz
Comprehensive quiz covering Java fundamentals including OOP concepts, exception handling, strings, arrays, loops, Swing GUI components, and basic syntax
Questions
String constructor cannot be passed
- char arrays
- int arrays
- byte arrays
- Strings
String objects are immutable. This means they
- must be initialized
- cannot be deleted
- cannot be changed
- None of the above
What class cannot be instantiated
- Final
- Concrete
- Abstract
- Polymorphic
Which class in Java does not extends an existing class
- Integer
- Object
- String
- Class
Composition is also known as the
- knows-a relationship
- has-a relationship
- uses-a relationship
- is-a relationship
Superclass methods with this level of access cannot be called from subclasses
- private
- public
- protected
- package
Which method changes the text the label displays?
- changeText
- setText
- ChangeLabel
- setLabel
Exceptions can be thrown by
- the Java Virtual Machine
- code in a try block
- calls from a try block to other methods
- All of the above
All exception classes inherit, either directly or indirectly from
- class Error
- class RuntimeException
- class Throwable
- None of the above
Which is not a GUI component?
- String
- Button
- Menu
- Combo box
What will be the output of the program?
- finished
- Exception
- Compilation fails.
- Arithmetic Exception
Which one create an anonymous inner class from within class Bar?
- Boo f = new Boo(24) { };
- Boo f = new Bar() { };
- Bar f = new Boo(String s) { };
- Boo f = new Boo.Bar(String s) { };
Which constructs an anonymous inner class instance?
- Runnable r = new Runnable() { };
- Runnable r = new Runnable(public void run() { });
- Runnable r = new Runnable { public void run(){}};
- System.out.println(new Runnable() {public void run() { }});
Which is true about an anonymous inner class?
- Extend exactly one class and implement exactly one interface
- Extend exactly one class and implement multiple interfaces
- Extend exactly one class or implement exactly one interface
- implement multiple interface
What are Wrapper classes?
- Classes that wraps functionality of an existing class.
- Classes that allow primitive types to be accessed as objects
- Both of the above.
- None of the above.
What is Abstraction?
- defines different methods of same type.
- the ability of an object to take on many forms.
- A summary of a Class.
- It refers to the ability to make a class abstract in OOP.
Besides Object all Exceptions and Errors are descended from what class?
- Extends
- Object
- Throwable
- Throws
What clause identifies a method as one that may throw an IOException or a WidgetException?
- throws IoException, WidgetException
- catch IOException, WidgetException
- throws Exception, WidgetException
- throws WidgetException. IOException
The method used to arrange for a button to notify another object when it is clicked later is?
- addMouseListener
- addListener
- addObjectListener
- addActionListener
What is the component that provides a box for writing one line of text in a GUI application?
- JTextField
- JMultiLineField
- JLabelField
- JTextArea
The import statement needed to use JOptionPane is
- import javax.Swing.JOptionPane ;
- import javax.swing.JOptionPane ;
- import java.swing.JOptionPane ;
- import javac.swing.JOptionPane ;
String s1 = "Hello", s2 = "Hi"; //Which code exchanges their values?
- String temp = s2; s2 = s1; s2 = temp;
- String s1 = temp; s1 = s2; s1 = temp;
- String temp = s1; s1 = s2; s2 = temp;
- String temp = s1; s1 = s2; s1 = temp;
Which expression is true if and only if x is NOT a upper-case letter. x is a char variable
- x<'A' && x >'Z'
- x<'a' || x >'z'
- x<'a' && x >'z'
- x<'A' || x >'Z'
Consider the code given, what is the output of the code above?
- 30
- Compiler Error
- Runtime Error
- Exception
In the main method of MyClassTester, how many objects of type MyClass are created?
- 1
- 2
- 3
- 4
Which keyword do you use to create a new instance of an object?
- this
- object
- new
- class
When is it OK to have an overloaded method that has a different return type?
- Only when the parameter list is also different
- Never
- Always
- At compilation time
for(int i = 0; i < 10; i++) How many times does "i<10" execute?
- 9 times
- 10 times
- 11 times
- compile time error
In Java, an array starts counting from...
- 0
- 2
- 1
- begin
An if statement can contain how many else if statements?
- Only two
- As many as you want
- None
- One
Which variable type would you use for a city name?
- int
- String
- double
- float
Which method prints text in a Java program?
- System.out()
- out.write.Text()
- System.out.println()
- System.printText()
Which method is the starting point for all Java programs?
- void
- public
- class
- main
Complete the statement: The JVM
- compiles source files into object files.
- compiles source files into machine code.
- translates bytecode into machine code.
- executes a java program and creates an executable file.
How are Java applications distributed?
- Using .java source files
- Using Java archive with .exe extension
- Using Java archive with .jar extension
- Using Java archive with .jvm extension
What is the extension for Java source code files?
- .cpp
- .java
- .c
- .jpp
What is the return type of the method?
- float
- double
- public
- int
To distribute your app to different platforms, how many Java version do you need to create?
- Two versions
- One for each platform
- Just one version
- Ask Prof. Itauma