With these two methods, which one runs for whatType(r)?
String whatType(Region r) { return "Got Region"; }
String whatType(RectRegion rr) { return "Got RectRegion"; }
Region r = new RectRegion();whatType(Region r)Java picks among overloads by the type of the argument as written, andris declared aRegion.whatType(RectRegion rr)The object is aRectRegion, butris declared aRegion, and the type is what chooses the overload.- Neither: it doesn’t compileTwo methods with the same name are fine when their parameters differ.
Finish
PointC: the first constructor sets both fields, and the second makes a point whose x and y are both both, by calling the first.class PointC {
double x;
double y;
PointC(double x, double y) {
}
PointC(double both) {
}
}
PointC p = new PointC(1.0, 2.0);
PointC q = new PointC(3.0);
double x;
double y;
PointC(double x, double y) {
}
PointC(double both) {
}
}
PointC p = new PointC(1.0, 2.0);
PointC q = new PointC(3.0);
PointC has no equals method written. What is new PointC(1.0, 2.0).equals(new PointC(1.0, 2.0))?falseWithout its ownequals, a class compares references, like==, and these are two different objects.trueThat’s what a record would say: a record writes anequalsthat compares the fields. A class doesn’t get one.- It doesn’t compileEvery class has an
equals; it’s just the one that compares references.
Px.size is static. Which of these calls it the way Pict.java does?Px.size("width", w)Astaticmethod is called on the class’s name, with no object in front.new Px().size("width", w)A static method doesn’t need an object, andnew Px()doesn’t compile: the constructor isprivate.size("width", w)sizeneedsPx.in front, unless the call is insidePxitself.
What does each one evaluate to? (Write a
double with its .0.)(int) 7.9 is (int) Math.round(7.5) is (double) 1 / 4 is (double) (1 / 4) is In your own program,
c is a Circle and r is a Raster. Which lines compile? Select all that do.int rad = c.radius();A record writes apublicaccessor for each field.int rad = c.radius;A record’s fields areprivate, andCircleis in another file,Pict.java.int h = r.height();height()is a methodRasterlets anyone call.int h = r.height;Rasterdeclaresheightas aprivatefield.