1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which of the following is a valid way to create an array in Java?
1. int[] arr = new int[5];
2. array int arr = new int[5];
3. int arr = new int[5];
4. int arr[] = 5;
*Answer:* 1. int[] arr = new int[5];
What is the default value of a boolean variable in Java?
false
2. true
3. undefined
Answer: 1. false
What is the result of the expression: 10 % 3?
1. 10
2. 1
3. 0
4. 3
Answer: 2. 1
4. Which of the following is a benefit of using inheritance?
1. Increased complexity
2. More memory usage
3. Slower execution
4. Code reusability
*Answer:* 4. Code reusability
5. All variables in Java must be declared before they can be used.
1. TRUE
2. FALSE
Answer: 1. TRUE
What is the data type of the variable "name" if it is declared as follows: name = "John";?
1. double
2. int
3. String
4. char
Answer: 3. String
What is polymorphism in object-oriented programming?
1. Ability to create multiple classes
2. Ability to encapsulate data
3. Ability to inherit properties
4. Ability to take many forms
Answer: 4. Ability to take many forms
9. The value of a variable can be changed after it has been declared.
1. TRUE
2. FALSE
Answer: 1. TRUE
What is a variable in Java?
1. A data type
2. A container to store data
3. To create methods
4. A method of outputting data
*Answer:* 2. A container to store data
Which of the following methods can be used to find the length of a one-dimensional array in Java?
1. arr.length()
2. arr.length
3. length(arr)
4. size(arr)
Answer: 2. arr.length
Program tasks are listed inside the main() method in Java.
1. FALSE
2. TRUE
Answer: 2. TRUE
In Java, which keyword is used to refer to the parent class in a subclass?
1. parent
2. super
3. this
4. base
*Answer:* 2. super
What is the output of the following code: System.out.println(5 + 3)?
1. 5
2. 53
3. 8
4. Error
*Answer:* 3. 8
Which of the following is the correct way to declare a method in Java?
1. methodName void()
2. void methodName()
3. void methodName()
4. method voidName()
Answer: 2. void methodName()
What is the syntax for declaring a variable in Java?
1. type variableName;
2. variableName = value;
3. value = variableName;
4. type variableName = value;
Answer: 1. type variableName;
---
How do you access the third element of an array named 'arr' in Java?
1. arr(3)
2. arr(2)
3. arr[3]
4. arr[2]
Answer: 4. arr[2]
. Which of the following keywords is used to create a new class in Java
1. create
2. new
3. define
4. class
Answer: 4. class
### 19. Which of the following is an example of compile-time polymorphism?
1. Interface Implementation
2. Method Overloading
3. Abstract Classes
4. Method Overriding
Answer: 2. Method Overloading
What is the primary purpose of inheritance in object-oriented programming?
1. To declare variables
2. To create a new class from an existing class
3. To implement interfaces
4. To define a method
*Answer:* 2. To create a new class from an existing class
21. What is the purpose of the 'enum' keyword in Java?
1. Implement an interface
2. To create a new class
3. To define a set of named constants
4. To declare a variable
Answer: 3. To define a set of named constants
22. Which of the following is a valid way to declare a constant in Java?
1. final int x = 10;
2. const int x = 10;
3. int x = 10;
4. static int x = 10;
Answer: 1. final int x = 10;
What is the purpose of the 'static' keyword in Java
1. To create an instance of a class
2. To create a constant variable
3. To define a method that belongs to the class rather than instances
4. To indicate a variable is private
Answer: 3. To define a method that belongs to the class rather than instances
24. In which programming language is polymorphism commonly implemented through interfaces?
1. C++
2. Java
3. Python
4. JavaScript
Answer: 2. Java
### 25. What is the main advantage of using polymorphism in object-oriented programming?
1. To restrict access to class members
2. To allow methods to be defined in multiple ways
3. To improve memory usage
4. To increase the complexity of the code
Answer: 2. To allow methods to be defined in multiple ways
26. Which of the following keywords is used to inherit a class in Java?
1. extends
2. super
3. implements
Answer: 1. extends
27. Can an enum in Java implement interfaces?
1. TRUE
2. FALSE
Answer: 1. TRUE
28. The System.out.println() method is used to print output to the console in Java.
1. FALSE
2. TRUE
Answer: 2. TRUE