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

These are some java questions, could anyone can help me with them? thx! 1 Which

ID: 3767200 • Letter: T

Question

These are some java questions, could anyone can help me with them? thx!

1

Which of the following statements tests for CONTENT equality?

Select one:

a. if ( x == "Hello" ) { ... }

b. if ( x.equals( "Hello" ) ) { ... }

c. if ( x != "Hello" ) { ... }

d. if ( x.contains( "Hello" ) ) { ... }

e. None of the above

2

Which comparison below is acceptable in Java syntax if the following declarations are made?

Point p1 = new Point( 3, 4 );
Point p2 = new Point( 5, 6 );

Select one:

a. p1.getX() > p2.getX()

b. p1.setX(5) == p2.setX(5)

c. p1 < p2

d. all of the above

e. none of the first 3 are acceptable syntax in Java

3

Which of the following statements creates a composition (or aggregation) relationship?

Select one:

a. public doSomething(Boo b){ ...}

b. return new Boo();

c. if ( myThing == b ) { ... }

d. private Boo myThing;

e. Boo Hoo

4

Which of the following things may an abstract class contain in addition to abstract methods?

Select one:

a. method definitions with implementations

b. instance variable declarations

c. constructor definitions with implementations

d. class constants (final variables)

e. All of the above.

5

What is the difference between an abstract class and a concrete class?

Select one:

a. An abstract class may NOT be extended.

b. An abstract class may NOT be instantiated.

c. All methods in an abstract class must be abstract.

d. A reference variable cannot have an abstract class as its static type.

e. All of the above.

6

Which of the following is true about a concrete class?

Select one:

a. A concrete class may be extended.

b. A concrete class may be instantiated.

c. A concrete may NOT contain abstract methods.

d. All of the above.

e. None of the above.

7

Which of the following is true?

Select one:

a. A class extends exactly one other class and may implement any number of interfaces.

b. A class may extend at most one concrete class, may extend any number of abstract classes, and may implement any number of interfaces.

c. A class may extend one concrete class and also one abstract class, and may implement any number of interfaces.

d. A class may extend exactly one other class, OR may implement any number of interfaces, but not both.

Explanation / Answer

1.

Solution:

The statement to test for CONTENT equality in java is string.equals(string2)

The option that is most suitable to test for CONTENT equality is:

if(x.equals(“Hello”))

{

      …….

}

Hence, the correct option is b)

2.

Solution:

The first option accesses the x coordinate of the point p1 and x coordinate of the point p2 and then the values are compared but the value of x of point p1, that is 3 is not greater than the value of x of point p2 that is 5. So, it is rejected. Similarly, the options b and c are also incorrect.

The correct option is e)

3.

Solution:

The aggregation represents a HAS-A relationship. Here, the option d) is correct because there is access specifier private and myThing is member of the class Boo

The correct option is d)

4.

Solution:

An abstract class contains the method definitions with implementation in addition to abstract classes. Thus, an abstract class implements all the abstract methods.

The correct option is a)

5.

Solution

The abstract classes cannot be instantiated but can be sub classed. Abstract classes cannot be instantiated at all. It is not necessary that the abstract methods must be declared in a class. We can declare a class abstract without having any abstract methods.

The difference is that a reference variable cannot have an abstract class as its static type.

The correct option is d)

6.

Instantiation is always possible for concrete class, so the statement that an abstract class may be instantiated is false. The concrete class may not contain abstract methods.is true.

Thus, the correct option is c)

7.

A class may extend at most one concrete class, may extend any number of abstract classes and may implement any number of interfaces.

The correct option is b)

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