Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Those are JAVA OOP questions, Please help QUESTION 1 Which of the following is t

ID: 3677959 • Letter: T

Question

Those are JAVA OOP questions, Please help

QUESTION 1

Which of the following is true?

Abstract and final can be declared on a class

Abstract and final are contradictory and cannot be declared on a class

Interfaces can declared as private

Interface methods can be declared private

QUESTION 2

Suppose:

ArrayList list = new ArrayList<>();

Which of the following operations are correct?

list.add("Red");

list.add(new Integer(100));

list.add(new java.util.Date());

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() {}
...
}

No particular methods are required

methodA

methodB

methodA and methodB

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() {}
...
}

InterfaceA obj = new ClassA();

InterfaceB obj = new ClassA();

InterfaceA obj = new ClassB();

InterfaceB obj = new ClassB();

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);

[Sarah, Kathy]

[Sarah, +, Kathy]

[Sarah, Kathy, +]

[Sarah, +, Kathy, +]

No output because the program goes into an infinite loop

QUESTION 6

Is ArrayList a subclass of ArrayList?

Yes

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"]?"

x.add("Chicago");

x.add(0, "Chicago");

x.add(1, "Chicago");

x.add(2, "Chicago");

QUESTION 8

Which of the following code is correct?

ArrayList list = new ArrayList<>(); list.add(5.2);

ArrayList list = new ArrayList<>(); list.add(5.2);

ArrayList list = new ArrayList<>(); list.add(5);

ArrayList list = new ArrayList<>(); list.add("5");

QUESTION 9

What is the size of a variable of type double in Java?

2 bytes

4 bytes

8 bytes

It depends on the compiler setting

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?

Gender g = "FEMALE";

Gender g = Gender.FEMALE;

Gender g = new Gender(FEMALE);

Gender g = Gender->FEMALE;

QUESTION 11

Given:

A and B are classes
C and D are interfaces

Which of the following cannot be true?

B extends A

A implements B

A implements C

B implements C, D

QUESTION 12

Choose the appropriate data type for this value: 1

int

double

String

boolean

QUESTION 13

To create a list to store integers, use

ArrayListlist = new ArrayList();

ArrayList list = new ArrayList();

ArrayList list = new ArrayList<>();

ArrayList list = new ArrayList();

QUESTION 14

The last value in an array called ar can be found at index:

0

1

ar.length

ar.length - 1

QUESTION 15

Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[4]?

2

3

4

5

QUESTION 16

Which of the following statements is true?

A static variable cannot have its value set in a constructor

A static variable must be declared final

An instance variable can't be declared final

A static method can't access an instance variable

Only a static method can access a static variable

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

Explanation / Answer

QUESTION 1--   A.Abstract and final can be declared on a class

QUESTION 2--A.list.add("Red");

QUESTION 3--A.No particular methods are required

QUESTION 4--D.InterfaceB obj = new ClassB();

QUESTION 5--E.No output because the program goes into an infinite loop

QUESTION 6--A.Yes

QUESTION 7--C.x.add(1, "Chicago");

QUESTION 8--All are correct(A,B,C,D)

QUESTION 9--C.8 bytes

QUESTION 10--Gender g = Gender.FEMALE;

QUESTION 11--A implements B

QUESTION 12--A.int,B.double,D.boolean

QUESTION 13--C.ArrayList list = new ArrayList<>();

QUESTION 14--D.ar.length - 1

QUESTION 15--D.5

QUESTION 16--E.Only a static method can access a static variable

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote