Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For any object obj, a call obj.getClass().getName() returns the name of the obj's class. Suppose System.out.println(new A() + + + new B()); displays

For any object obj, a call obj.getClass().getName() returns the name of the obj's class.

Suppose System.out.println(new A() + " + " + new B()); displays A + B

Which of the following implementations would produce that result?

I. Class A has a method

public String toString() { return "A"; }

and class B has a method

public String toString() { return "B"; }

II. Both class A and class B extend class X that has a method

public String toString() { return getClass().getname(); }

III. Both class A and class B extend an abstract class X that has methods

public abstract String getName();

public String toString() { return getname(); }

Class A has a method

public String toString() { return "A"; }

and class B has a method

public String toString() { return "B"; }

(A) I only

(B) II only

(C) I and II

(D) II and III

(E) I, II, and III

Consider the following class:

public class SaleItem implements Comparable

{

public SaleItem(int p) { prcice = p; }

< Comparison method header > { < Code not shown > }

public String toString() { return String.valueOf(price); }

private int price;

}

Which of the following could replace < Comparison method header > to make this class

compile with no errors?

I. public int compare(SatleItem item1, SaleItem item2)

II. public boolean compareTo(SaleItem item1)

III. public int compareTo(Object obj)

Page 9 of 14

(A) I only

(B) II only

(C) III only

(D) I or II

(E) II or III

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions