cc103 midterm exam coverage
cc103 midterm exam coverage
Cabanatuan City
Tel. No. (044) 960-1630
Name:
Course:
1. Which of the following is the correct syntax for defining a class in Java?
A) class MyClass() {} B) class MyClass {}
C) public MyClass() {} D) MyClass class {}
2. What is the default value of a boolean variable in Java?
A) true B) false
C) 0 D) null
3. Which of the following is not a valid Java data type?
A) int B) float
C) char D) integer
4. Which of the following is true about the "String" class in Java?
A) Strings are mutable. B) Strings are immutable.
C) Strings can only be used with the StringBuffer class.
D) Strings can be compared using == operator.
5. What is the result of the following Java code?
int x = 10;
x = x + 5;
A) 10 B) 5
C) 15 D) Error
6. Which of these methods is used to find the length of a string in Java?
A) length() B) size()
C) getLength() D) count()
7. What is the output of the following Java code?
int x = 5;
System.out.println(x++);
A) 5 B) 6
C) 4 D) Error
8. What is the default value of an integer in Java?
A) 0 B) null
C) false D) undefined
9. What will be the output of the following code?
System.out.println(10 / 3);
A) 3.0 B) 3
C) 3.33 D) Error
10. Which of the following is true about method overloading in Java?
A) Methods must have the same name and parameters.
B) Methods must have different names.
C) Methods must have the same return type.
D) Methods can have the same name but different parameters.
11. Which package is needed to work with JFrame in Java?
A) java.awt B) javax.swing
C) java.util D) java.io
12. How do you create a new instance of JFrame?
A) JFrame frame = new JFrame(); B) JFrame frame = new JFrame();
C) frame = new JFrame(); D) new JFrame frame();
13. Which method is used to set the title of a JFrame?
A) setTitle() B) setName()
C) setWindowTitle() D) setHeader()
14. What is the default close operation for a JFrame?
A) JFrame.EXIT_ON_CLOSE B) JFrame.DISPOSE_ON_CLOSE
C) JFrame.DO_NOTHING_ON_CLOSE D) JFrame.HIDE_ON_CLOSE
15. What method is used to set the size of a JFrame?
A) frame.setSize(width, height); B) frame.setDimensions(width, height);
C) frame.resize(width, height); D) frame.setDimensions();
16. How do you close a JFrame when clicking the close button?
A) frame.close();
B) frame.setCloseAction(JFrame.EXIT_ON_CLOSE);
C) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
D) frame.closeWindow();
17. How do you change the background color of a JFrame?
A) frame.setBackground(Color.RED); B) frame.setColor(Color.RED);
C) frame.setBgColor(Color.RED); D) frame.setWindowColor(Color.RED);
18. Which layout manager is the default for JFrame?
A) GridLayout B) FlowLayout
C) BorderLayout D) GridBagLayout
19. Which package is required to use JOptionPane in Java?
A) java.awt B) javax.swing
C) java.util D) java.io
20. Which method is used to display a simple message dialog in JOptionPane?
A) JOptionPane.showDialog() B) JOptionPane.showMessageDialog()
C) JOptionPane.displayMessage() D) JOptionPane.showTextDialog()
21. What type of icon can be shown in a message dialog using JOptionPane?
A) JOptionPane.INFORMATION_MESSAGE B) JOptionPane.WARNING_MESSAGE
C) JOptionPane.ERROR_MESSAGE D) All of the above
22. Which method in JOptionPane is used to display a confirmation dialog with Yes/No options?
A) JOptionPane.showConfirmDialog() B) JOptionPane.showChoiceDialog()
C) JOptionPane.showYesNoDialog() D) JOptionPane.getConfirmationDialog()
23. What is the return type of the showInputDialog method?
A) int B) String
C) Boolean D) Object
24. Which method can be used to set the title of a dialog in JOptionPane?
A) setTitle() B) setDialogTitle()
C) setDialogHeader() D) JOptionPane.showMessageDialog()
25. Which of the following methods in JOptionPane can be used to show an error message?
A) showMessageDialog() B) showErrorDialog()
C) showError() D) showWarningDialog()
26. Which of the following return types is possible when using JOptionPane.showConfirmDialog()?
A) String B) int
C) Boolean D) Object
27. Which of the following is the correct syntax to print a message to the console in Java?
A) System.out.println("Hello, World!"); B) print("Hello, World!");
C) console.log("Hello, World!"); D) echo "Hello, World!";
28. Which of these is a primitive data type in Java?
A) String B) Integer
C) int D) ArrayList
29. What does the final keyword mean in Java?
A) It defines a variable as immutable (constant). B) It defines a method that cannot be overridden.
C) It defines a class that cannot be subclassed. D) All of the above.
30. In Java, which keyword is used to create an object of a class?
A) new B) class
C) object D) create
31. Which method is used to get the length of an array in Java?
A) array.size() B) array.length()
C) array.length D) array.getLength()
32. Which of the following is a valid Java loop structure?
A) loop B) repeat
C) for D) foreach
33. What is the index of the first element in an array in Java?
A) 0 B) 1
C) -1 D) 10
34. What is the default value of an integer array in Java?
A) null B) 0
C) NaN D) undefined
35. What will be the output of the following code?
int[] arr = {10, 20, 30};
System.out.println(arr[1]);
A) 10 B) 20
C) 30 D) Error
36. What does the following code do?
int[] arr = new int[10];
arr[0] = 5;
System.out.println(arr[0]);
A) Prints 0 B) Prints 5
C) Throws an exception D) Prints null
37. What is the default value of elements in an array of boolean in Java?
A) false B) true
C) null D) 0
38. What will be the output of the following code?
int[] arr = new int[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
System.out.println(arr[2]);
A) 10 B) 20
C) 30 D) 0