0% found this document useful (0 votes)
12 views7 pages

Bài 1-6

The document contains a series of multiple-choice questions related to Java programming concepts, including variable declaration, access modifiers, object-oriented programming features, and array handling. Each question includes options with the correct answers marked. The content is designed to test knowledge of Java syntax and principles.

Uploaded by

phattai16767
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Bài 1-6

The document contains a series of multiple-choice questions related to Java programming concepts, including variable declaration, access modifiers, object-oriented programming features, and array handling. Each question includes options with the correct answers marked. The content is designed to test knowledge of Java syntax and principles.

Uploaded by

phattai16767
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

1. (0.

25 Point)
What is the exact output of the following code?
double area = 3.5;
System.out.print("area");
System.out.print(area);
A. 3.53.5
B. 3.5 3.5
*C. area3.5
D. area 3.5
2. (0.25 Point)
What is the exact output of the following code?
System.out.print(1 + 2 + “1” + 1);
*A. 311
B. Compiler error
C. 1211
D. 5
3. (0.25 Point)
Which of the following are correct names for variables according to camelCase in Java
naming conventions?
A. Radius
B. RADIUS
*C. findArea
D. FindArea
4. (0.25 Point)
Which of the following are correct ways to declare variables?
*A. int length; int width;
B. int length; width;
C. int length, int width;
D. All of the above
5. (0.25 Point)
To declare a constant MAX_LENGTH inside a method with value 99.98, you write
A. final MAX_LENGTH = 99.98;
B. final int MAX_LENGTH = 99.98;
C. double MAX_LENGTH = 99.98;
*D. final double MAX_LENGTH = 99.98;
6. (0.25 Point)
What is the result of x:
int x = 45 / 4?
A. 10
*B. 11
C. 11.25
D. 12
7. (0.25 Point)
Which of the following expression results in a value 1?
A. 2 % 1
B. 15 % 4
C. 25 % 5
*D. 37 % 6
8. (0.25 Point)
You can cast a double value to ………..
A. byte
B. short
C. int
D. long
*E. All of the above
9. (0.25 Point)
Suppose a Scanner object is created as follows:

Scanner input = new Scanner(System.in);

What method do you use to read a String value?


*A. input.next();
B. input.nextLine();
C. input.Next();
D. All answer is false;
10. (0.25 Point)
What is the result of x & y:
int x = 1;
int y = x++ + ++x + x + x++ + x++ + ++x;
A. x = 1 & y = 6
*B. x = 6 & y = 20
C. x = 3 & y = 6
D. x = 3 & y = 20
11. (0.25 Point) Which keyword is used to prevent a class from being subclassed in Java?
A. static
*B. final
C. private
D. abstract
12. (0.25 Point)
Which of the following is not a valid access modifier in Java?
A. public
B. private
C. protected
*D. global
13. (0.25 Point)
Math.pow(4, 2) returns ?
A. 16
B. 2
C. Error
*D. 16.0
14. (0.25 Point)
Which of the following can be used to create an instance of a class?
*A. constructor
B. method
C. variable
D. operator
15. (0.25 Point)
Which of the following loops is guaranteed to execute at least once?
A. for
B. while
*C. do-while
D. foreach
16. (0.25 Point)
Which of the following is a feature of Object-Oriented Programming?
A. Encapsolation
B. Compilation
C. Algorithm
*D. Encapsulation
17. (0.25 Point)
What is method overriding in Java?
A. Defining multiple methods with the same name but different parameter types in the
same class.
*B. A subclass providing a specific implementation of a method that is already defined in
its superclass.
C. Calling two methods with the same name from different classes.
D. Changing the name of a method in a subclass.
18. (0.25 Point)
Which of the following best describes abstraction?
*A. Showing only the essential features and hiding the details
B. Using multiple inheritance in Java
C. Reusing code through inheritance
D. Defining a class without any methods
19. (0.25 Point)
In Java, what is the purpose of the super keyword?
A. To call a method in the current class
*B. To refer to the immediate parent class object
C. To access private members of a class
D. To call the destructor of a class
20. (0.25 Point)
Which access modifier allows a variable or method to be accessed within the same
package but not from outside the package?
A. public
B. protected
*C. default (no modifier)
D. private
21. (0.25 Point)
Which keyword is used to inherit a class in Java?
A. implements
*B. extends
C. inherits4444
D. superclass
22. (0.25 Point)
In Java, what does the == operator compare when used with object references?
A. The values inside the objects
B. The class type of the objects
*C. The memory addresses (references) of the objects
D. The hash codes of the objects
23. (0.25 Point)
Which of the following is true about constructors in Java?
A. They must have the same name as the class.
B. They cannot have a return type.
C. They are automatically called when an object is created.
*D. All of the above.
24. (0.25 Point)
Which of the following is used to define an interface in Java?
*A. interface
B. class
C. implements
D. import
25. (0.25 Point)
Which of the following is the correct way to declare an array in Java?
*A. int[] arr = new int[10];
B. int arr[] = new int[];
C. int arr[10];
D. int arr = new int[10];
26. (0.25 Point)
What is the default value of a boolean array in Java?
A. true
B. null
*C. false
D. 0
27. (0.25 Point)
Which method is used to get the number of elements in an ArrayList in Java?
A. size[]
*B. size()
C. length()
D. getSize()
28. (0.25 Point)
What will happen if you try to store more elements than the declared size of an array in
Java?
A. The extra elements will be ignored.
*B. ArrayIndexOutOfBoundsException will be thrown.
C. The array will automatically resize.
D. The program will compile but run with errors.
29. (0.25 Point)
Which of the following is the correct way to declare an array in Java?
*A. int[] arr = new int[10];
B. int arr[] = new int[];
C. int arr[10];
D. int arr = new int[10];
30. (0.25 Point)
What is the default value of a boolean array in Java?
A. true
B. null
*C. false
D. 0
31. (0.25 Point)
Which method is used to get the number of elements in an ArrayList in Java?
A. size[]
*B. size()
C. length()
D. getSize()
32. (0.25 Point)
What will happen if you try to store more elements than the declared size of an array in
Java?
A. The extra elements will be ignored.
*B. ArrayIndexOutOfBoundsException will be thrown.
C. The array will automatically resize.
D. The program will compile but run with errors.
33. (0.25 Point)
How do you convert an ArrayList to an array in Java?
A. ArrayList.toArrayList();
*B. ArrayList.toArray();
C. ArrayList.asArray();
D. ArrayList.convertArray();
34. (0.25 Point)
Which method would you use to find the length of a String in Java?
A. getSize()
B. length[]
*C. length()
D. size()
35. (0.25 Point)
What is the starting index of an array in Java?
*A. 0
B. 1
C. -1
D. It depends on the array type.
36. (0.25 Point)
Which of the following is correct to initialize an ArrayList with integer values in Java?
A. ArrayList<int> list = new ArrayList<>();
*B. ArrayList<Integer> list = new ArrayList<>();
C. ArrayList<> list = new ArrayList<int>();
D. ArrayList[] list = new ArrayList<Integer>();
37. (0.25 Point)
Which of the following is true about arrays in Java?
*A. Arrays have a fixed size once declared.
B. Arrays can dynamically resize.
C. Arrays can contain different types of elements.
D. The size of an array can be changed later.
38. (0.25 Point)
Which of the following is the correct way to compare two strings for equality in Java?
A. Using ==
B. Using compareTo()
*C. Using equals()
D. Using equalsIgnoreCase()
39. (0.25 Point)
What will the following code return?
String s1 = "hello";
String s2 = "hello";
boolean result = (s1 == s2);
A. false
*B. true
C. It will throw an exception.
D. It will not compile.
40. (0.25 Point)
Which of the following is true about abstract classes and interfaces in Java?
A. An abstract class can implement methods but an interface cannot.
B. A class can implement multiple interfaces but can extend only one abstract class.
C. An abstract class can have constructors, but an interface cannot.
*D. All of the above.

You might also like