For the GeometricObject and Circle classes in Listings 11.1 and 11.2, answer the following questions:
a. Assume that circle and object1 are created as follows:
Circle circle = new Circle(1);
GeometricObject object1 = new GeometricObject();
Are the following Boolean expressions true or false?
(circle instanceof GeometricObject)
(object instanceof GeometricObject)
(circle instanceof Circle)
(object instanceof Circle)
b. Can the following statements be compiled?
Circle circle = new Circle(5);
GeometricObject object = circle;
c. Can the following statements be compiled?
GeometricObject object = new GeometricObject();
Circle circle = (Circle)object;
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Software Engineering (10th Edition)
Digital Fundamentals (11th Edition)
Absolute Java (6th Edition)
Problem Solving with C++ (10th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
- Write a class Point with instance variables as: xCoordinate(int) and yCoordinate(int). Write public instance methods (getters & setters) for each instance variable. Now, write a class Circle with private instance variables as radius and Pi (value is 3.14). Write public setter, getter for radius, Area method for calculating Area, Draw method for radius. Formula for calculating area=pi*r^2 Formula for calculating radius= Math.sqrt (xCordinate^2+yCordinate^2) a. Extend a Circle class from Point class such as Class Circle extends Pointb. Write a Default constructor in Circle class that sets radius, xCoordinate & yCoordinate to some default value e.g. -1;c. Write a Parameterized constructor in Circle class which takes xCoordinate, yCoordinate and radius as a parameter.Now write a ColoredCirlce class with private instance variable as color (String) and public setter & getters. Extend the ColoredCircle from Circle and do the following operations.d. Write a default constructor…arrow_forwardChange the Fraction class so that its instance variables (numerator and denominator) are hidden (i.e. private). Check that the client class (after this change) will now not compile. Why does it not compile? Provide the changes to the Fraction class and the TestFraction class such that the program can work with the private instance variables by implementing appropriate accessor and mutator methods. import java.util.Scanner;//test programpublic class testfraction{public static void main(String[] args) {//create a Scanner objectScanner in = new Scanner(System.in);//create new fractionFraction frac = new Fraction();//declare numerator and denominatorint n=1,d;System.out.print("Enter Fraction's Numerator: ");//input numeratorn = in.nextInt();System.out.print("Enter Fraction's Denominator: ");//input denominatord = in.nextInt();//loop execute until the numerator is negativewhile(n>=0){//call input with n and dfrac.input(n, d);//call displayfrac.display();System.out.print("Enter…arrow_forwardIn this example, a Computer object keeps track of its amount of RAM and its OS version. It also has methods for upgrading the RAM and updating the OS. Two classes, a desktop computer, and a Phone, extend this class and implement its methods. A ComputerUpgrader object claims to be able to upgrade any Computer (that is, add more RAM and update the OS), but it really can't add more RAM to a phone, so it must check to make sure the Computer object it has been given isn't a Phone. This violates the ___ SOLID principle (chose the single best answer). Choose ADP OCP LSP ISP or DIP The Single Responsibility Principle (SRP)The Open-Closed Principle (OCP)The Liskov Substitution Principle (LSP)The Interface Segregation Principle (ISP)The Dependency Inversion Principle (DIP)arrow_forward
- Implement a class Season that represents a season during a specified year. For purposes of thisproblem, assume that the seasons in each year are, in order, 'Winter', 'Spring', 'Summer', 'Autumn' .__init__, __repr__A Season object is created by calling the constructor and supplying two optional arguments:1. season, defaults to 'Winter'2. calendar year, an int , defaults to 2023For the __repr__ , see the usage below: The next and prev methods modify a Season object by changing it to the next season or previousseason in sequence, respectively. Note that the seasons can "roll over" or "roll back" and that this maychange the year by +/-1. 1. During each year, the seasons occur in this sequence: 'Winter', 'Spring', 'Summer', 'Autumn' 2. next - change to next season, if the current season is Autumn then year will increase by 1 3. prev - change to previous season, if Winter then year will decrease by 1 Implement the == operator ( __eq__ method) to compare two Season…arrow_forwardWrite the Boat class in Java Eclipse. A Boat has a registered name, a number of cabins, and a length.a) Define the instance variables (data fields).b) Include 2 constructors (default and one that receives the Boat registeredname, number of cabins and its length as an input).c) Write accessors (getters) and mutators (setters) methods for the instancevariables on your own. Verify/correct the answers with the help of Eclipse.arrow_forwardSay we have a collection of animal classes, with each class represents a kind of animal. They all share a common ability of “speak”. Dog speak in the way of “Woof! Woof!”, cats speak in the way of “Meow! Meow!”, etc. In order to capture this common characteristic, we need an interface named Speakable: public interface Speakable { // put the method header here } Think about what method is needed for the Speakable interface? (what method can describe the speakable feature? ) We simply need one method speak() to print out the way that the animal “speaks”. Put the method header in the interface body. This method does not take any parameter and does not return any value. Be reminded that you only need to put the method header with a semicolon (abstract method) into the interface. BE NOTED: Adding an interface is different from adding a class. You need to click File tab -> New -> Interface, to add an interface file to the project. Now download Cat.java. Have them implement the…arrow_forward
- Say we have a collection of animal classes, with each class represents a kind of animal. They all share a common ability of “speak”. Dog speak in the way of “Woof! Woof!”, cats speak in the way of “Meow! Meow!”, etc. In order to capture this common characteristic, we need an interface named Speakable: public interface Speakable { // put the method header here } Think about what method is needed for the Speakable interface? (what method can describe the speakable feature? ) We simply need one method speak() to print out the way that the animal “speaks”. Put the method header in the interface body. This method does not take any parameter and does not return any value. Be reminded that you only need to put the method header with a semicolon (abstract method) into the interface. BE NOTED: Adding an interface is different from adding a class. You need to click File tab -> New -> Interface, to add an interface file to the project. Now download Dog.java. Have them implement the…arrow_forwardAre the fields in the following interface class fields or instance fields? public interface Quiz { int CORRECT = 1; int INCORRECT = 0;...} What visibility do they have?arrow_forwardGiven the following class, I need help writing a constructor that initializes all instance variables using appropriate parameters. I need to make sure it enforces the preconditions public class BrowserTab {private String title;private int id;/*** Creates a BrowserTab* @precondition title != null && id >= 0*/}arrow_forward
- Can it be two classes, the Calculator class must instantiate the CalculatorFrame class and the CalculatorFrame class must be where the calculator gets built.arrow_forwardWrite a class Point with instance variables as: xCoordinate(int) and yCoordinate(int). Write public instance methods (getters & setters) for each instance variable. Now, write a class Circle with private instance variables as radius and Pi (value is 3.14). Write public setter, getter for radius, Area method for calculating Area, Draw method for radius. Formula for calculating area=pi*r^2 Formula for calculating radius= sqrt (xCordinate^2+yCordinate^2) Extend a Circle class from Point class such as Class Circle extends Point Write a Default constructor in Circle class that sets radius, xCoordinate & yCoordinate to some default value e.g. -1; Write a Parameterized constructor in Circle class which takes xCoordinate, yCoordinate and radius as a parameter. E.g. Circle (int xCoordinate, int yCoordinate, double radius) { this.xCoordinate= xCoordinate; this.yCoordinate= yCoordinate;…arrow_forward*using java* Create a class AnimalCreate a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal(String name) //constructor public void makesSound()with the implementation printing out a generic animal sound. Next, override (add) the makesSound()method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don’t make sounds!)Note, you’ll also need a constructor in each of your subclasses which calls super(name) to initialize the common ‘name’ member of Animal. --- Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. ( you should observe the implementation of the makeSound() method called will be: cat -> from Cat class, dog-> from Dog class,…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,