Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Java Upcasting and Downcasting The answer is B, but I don't understand why... I am really confused about this topic in java... if possible,

# Java Upcasting and Downcasting

The answer is B, but I don't understand why... I am really confused about this topic in java...

if possible, please answer as clearly as possible. Many thanks!!!

// Program 1:

public class Test {

public static void main(String[] args) {

Object circle1 = new Circle();

Object circle2 = new Circle();

System.out.println(circle1.equals(circle2));

}

}

class Circle {

double radius;

public boolean equals(Circle circle) {

return this.radius == circle.radius;

}

}

// Program 2:

public class Test {

public static void main(String[] args) {

Object circle1 = new Circle();

Object circle2 = new Circle();

System.out.println(circle1.equals(circle2));

}

}

class Circle {

double radius;

public boolean equals(Object circle) {

return this.radius ==

((Circle)circle).radius;

}

}

19)

A) Program 1 displays true and Program 2 displays true

B) Program 1 displays false and Program 2 displays true

C) Program 1 displays true and Program 2 displays false

D) Program 1 displays false and Program 2 displays false

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions