Which of the following is true about interfaces:
An interface can have only non abstract methods.
All methods in an interface must be abstract.
A class can only implement one interface.
None of the items listed.
Can not contain constants but can have variables.
What is the rule for a super reference in a constructor?
It must be in the parent class' constructor.
You cannot use super in a constructor.
It must be the last line of the constructor in the child class.
Only one child class can use it.
It must be the first line of the constructor in the child class.
Consider the following class definition.
public class WhatsIt {
private int length;
private int width;
public int getArea () {
// implementation not shown
}
private int getPerimeter () {
// implementation not shown
}
}
A child class Thingy that extends WhatsIt would have access to:
width, length, getPerimeter()
getPerimeter()
All of the items listed.
getArea()
width, length, getArea()
Questions 18 - 20 pertain to the following class, Point:
public class Point {
private double x;
private double y;
public Point() {
this (0, 0);
}
public Point(double a, double b) {
/* missing code */
}
// ... other methods not shown
}
Which of the following correctly implements the equals method?
public boolean equals(Point p) {
return (x == p.x && y == p.y );
}
public void equals(Point p) {
System.out.println(x == p.x && y == p.y);
}
public void equals(Point p) {
return (x == p.x && y == p.y );
}
public boolean equals(Point p) {
return (x == Point.x && y == Point.y);
}
public boolean equals(Point p) {
System.out.println(x == p.x && y == p.y);
}
The default constructor sets x and y to (0, 0) by calling the second constructor. What could be used to replace /* missing code */ so that this works as intended?
a = 0; b = 0;
this (x, y);
this(0, 0);
x = a; y = b;
a = x; b = y;
Which of the following correctly implements a mutator method for Point?
public double getX() {
return x;
}
public void setCoordinates (double a, double b) {
x = a;
y = b;
}
None of the items listed.
public double getX() {
return a;
}
public void setCoordinates (double a, double b) {
Point p = new Point(a,b);
}Q1. The following is true about interfaces:
All methods in an interface must be abstract
This is because the interface will have the abstract methods for applying the multiple inheritances, which means that one class can apply multiple interfaces.
Q2. The rule for a super reference in a constructor is that:
It must be the first line of the constructor in the child class
The super() is called explicitly in the child class constructor, thus enabling the parent constructor to be called from the subclass i.e. child class. The first line will have the parent constructor which will make sure that the parent constructor is called before the child constructor
Q3.
The child class Thingy that extends WhatsIt would have access
to:
getArea ()
this is because the width, length, getPerimeter() are private and will just be available inside the WhatsIt class. The getArea is public and thus available for use in child class.
**Please Hit Like if you appreciate my answer. For further doubts on the question or answer please drop a comment, I'll be happy to help. Thanks for posting.**
Which of the following is true about interfaces: An interface can have only non abstract methods....
need some help on these a little contested
right now the answers i have are
18
: d
19
: e
20
: c
would appriacte why i am right or wrong thank you
sorry i added the picture of 17 by mistake
19. The default constructor sets x and y to (0,0) by calling the second constructor. What could be used to replace / missing code */ so that this works as intended? a b = = 0; 0;...
m The interface Measurable is defined as the following: /** An interface for methods that return the perimeter and area of an object. */ public interface Measurable { public double getPerimeter(); public double getArea(); } The class Rectangle implements the interface. The incomplete program is written as follows: 1 public class Rectangle 2 { private double width; private double height; public Rectangle(double w, double h) { width = w; height h; } { 3 4 5 6 7 8 9...
In Pl you will create an interface, Drawable, and an abstract class Polygon. The Point class is provided. Briefly go over the JavaDocs comments to see what is available to you. «interface Drawable +printToConsole(): void Polygon - points : List<Point> - colour : String Point + Polygon(String colour) + getPoints(): List<Point> + addPoint(Point p): void + equals(Object other): boolean +getArea(): double • The Polygon constructor initializes the List to a List collection of your choosing • add Point: Adds a...
Can the folllowing be done in Java, can code for all classes and code for the interface be shown please. Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometriObject class for finding the larger of two GeometricObject objects. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles. The GeometricObject class is provided below: public abstract class GeometricObject { private...
Create a UML diagram with 3 lines per class/interface including all constructors. public class Point { public double X, Y; public Point() { this(0, 0); } public Point(double newX, double newY) { X = newX; Y = newY; } public static double distance(Point A, Point B) { return Math.sqrt(Math.pow(A.X-B.X, 2) + Math.pow(A.Y-B.Y, 2)); } } public interface Polygon { public int getNumberOfSides(); public double getPerimeter(); public double getArea(); } public abstract class Simple_polygon implements Polygon{ public Point...
In java please: TotalCostForTicket interface Create interface that includes one variable taxRate which is .09. It also includes an abstract method calculateTotalPrice which has no parameters and returns a value of type double. public abstract class Ticket { //There is a public static instance variable of type double for the basePrice. public static double basePrice; // private int theaterNumber; private int seatNumber; private boolean isTicketSold; private boolean isTicketReserved; public Ticket(int theaterNumber, int seatNumber) { this.theaterNumber = theaterNumber; this.seatNumber = seatNumber;...
write a completed program (included the main) for the Q: add an
equals method to each of the Rectangle circle and triangle classes
introduced in this chapter. two shapes are considered equal if
their fields have equivalent values. based on
public class Circle implements Shape f private double radius; // Constructs a new circle with the given radius. public Circle (double radius) f this.radius - radius; // Returns the area of this circle. public double getArea) return Math.PI *radius *...
Susceptible.java
interface Susceptible
{
public boolean infect(Disease disease);
public void forceInfection(Disease disease);
public Disease getCurrentDisease();
public void setImmune();
public boolean isImmune();
public Point getPosition();
}
Movable.java
interface Movable
{
public void move(int step);
}
public class Point {
private int xCoordinate;
private int yCoordinate;
/**
* Creates a point at the origin (0,0) and colour set to black
*/
public Point(){
xCoordinate = 0;
yCoordinate = 0;
}
/**
* Creates a new point at a given coordinate and colour...
Must be in Java.
Show proper reasoning with step by step
process.
Comment on the code please and show proper
indentation.
Use simplicity.
Must match the exact Output.
CODE GIVEN:
LineSegment.java
LineSegmentTest.java
Point.java
public class Point {
private double x, y; // x and y coordinates of
point
/**
* Creates an instance of Point with the provided coordinates
* @param inX the x coordinate
* @param inY the y coordinate
*/
public Point (double inX, double inY) {
this.x...
We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private int x = 0; // constructor public Class1(int x) { this.x = x; } // instance methods public double myMethod1(double x, double y) { return x - y; } public void myMethod2(int x) { System.out.println(x); } public String myMethod3(String x) { return "hi " + x; } } We have also written the following Class2 class: class Class2 implements SecretInterface { // instance variable...