Question: Those are JAVA OOP questions, Please help QUESTION 1 Which of the following is true? A. Abstract and final can be declared on a class
Those are JAVA OOP questions, Please help
QUESTION 1
Which of the following is true?
| A. | Abstract and final can be declared on a class | |
| B. | Abstract and final are contradictory and cannot be declared on a class | |
| C. | Interfaces can declared as private | |
| D. | Interface methods can be declared private |
QUESTION 2
Suppose:
ArrayList list = new ArrayList<>();
Which of the following operations are correct?
| A. | list.add("Red"); | |
| B. | list.add(new Integer(100)); | |
| C. | list.add(new java.util.Date()); | |
| D. | list.add(new ArrayList()); |
QUESTION 3
What is the minimum number of methods that must be defined in classB for it to compile with no errors? public interface InterfaceA { void methodA(); } public interface InterfaceB extends InterfaceA { void methodB(); } public class ClassA implements InterfaceA { public void methodA() {} public void methodB() {} } public class ClassB extends ClassA implements InterfaceB { public ClassB() {} ... }
| A. | No particular methods are required | |
| B. | methodA | |
| C. | methodB | |
| D. | methodA and methodB | |
| E. | methodA , methodB, and toString |
QUESTION 4
Which of the following statements causes a syntax error? public interface InterfaceA { void methodA(); } public interface InterfaceB extends InterfaceA { void methodB(); } public class ClassA implements InterfaceA { public void methodA() {} public void methodB() {} } public class ClassB extends ClassA implements InterfaceB { public ClassB() {} ... }
| A. | InterfaceA obj = new ClassA(); | |
| B. | InterfaceB obj = new ClassA(); | |
| C. | InterfaceA obj = new ClassB(); | |
| D. | InterfaceB obj = new ClassB(); | |
| E. | ClassA obj = new ClassB(); |
QUESTION 5
What is the output of the following code segment? ArrayList names = new ArrayList(); names.add("Sarah"); names.add("Kathy"); for (int i = 1; i < names.size(); i++) { names.add(i, "+"); } System.out.println(names);
| A. | [Sarah, Kathy] | |
| B. | [Sarah, +, Kathy] | |
| C. | [Sarah, Kathy, +] | |
| D. | [Sarah, +, Kathy, +] | |
| E. | No output because the program goes into an infinite loop |
QUESTION 6
Is ArrayList a subclass of ArrayList?
| A. | Yes | |
| B. | No |
QUESTION 7
Suppose ArrayList x contains two strings ["Atlanta", "St Louis"]. Which of the following methods will cause the list to become ["Atlanta", "Chicago", "St Louis"]?"
| A. | x.add("Chicago"); | |
| B. | x.add(0, "Chicago"); | |
| C. | x.add(1, "Chicago"); | |
| D. | x.add(2, "Chicago"); |
QUESTION 8
Which of the following code is correct?
| A. | ArrayList list = new ArrayList<>(); list.add(5.2); | |
| B. | ArrayList list = new ArrayList<>(); list.add(5.2); | |
| C. | ArrayList list = new ArrayList<>(); list.add(5); | |
| D. | ArrayList list = new ArrayList<>(); list.add("5"); |
QUESTION 9
What is the size of a variable of type double in Java?
| A. | 2 bytes | |
| B. | 4 bytes | |
| C. | 8 bytes | |
| D. | It depends on the compiler setting | |
| E. | It depends on the operating system |
QUESTION 10
The Gender enum is defined as: public enum Gender { FEMALE, MALE } Which of the following is correct for assigning a gender to a variable g of type Gender?
| A. | Gender g = "FEMALE"; | |
| B. | Gender g = Gender.FEMALE; | |
| C. | Gender g = new Gender(FEMALE); | |
| D. | Gender g = Gender->FEMALE; |
QUESTION 11
Given: A and B are classes C and D are interfaces Which of the following cannot be true?
| A. | B extends A | |
| B. | A implements B | |
| C. | A implements C | |
| D. | B implements C, D |
QUESTION 12
Choose the appropriate data type for this value: 1
| A. | int | |
| B. | double | |
| C. | String | |
| D. | boolean |
QUESTION 13
To create a list to store integers, use
| A. | ArrayListlist = new ArrayList(); | |
| B. | ArrayList list = new ArrayList(); | |
| C. | ArrayList list = new ArrayList<>(); | |
| D. | ArrayList list = new ArrayList(); |
QUESTION 14
The last value in an array called ar can be found at index:
| A. | 0 | |
| B. | 1 | |
| C. | ar.length | |
| D. | ar.length - 1 |
QUESTION 15
Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[4]?
| A. | 2 | |
| B. | 3 | |
| C. | 4 | |
| D. | 5 |
QUESTION 16
Which of the following statements is true?
| A. | A static variable cannot have its value set in a constructor | |
| B. | A static variable must be declared final | |
| C. | An instance variable can't be declared final | |
| D. | A static method can't access an instance variable | |
| E. | Only a static method can access a static variable |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
