Identify the problems in the following code:
1 public class Circle {
2 private double radius;
3
4 public Circle (double radius) {
5 radius = radius;
6 }
7
8 public double getRadius() {
9 return radius;
10 }
11
12 public double getArea() {
13 return radius * radius * Math.PI;
14 }
15 }
16
17 class B extends Circle {
18 private double length;
19
20 B(double radius, double length) {
21 Circle(radius);
27 length = length;
23 }
24
25 @Override
26 public double getArea() {
27 return getArea() * length;
28 }
29 }
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
Introduction To Programming Using Visual Basic (11th Edition)
Programming in C
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Database Concepts (7th Edition)
Concepts of Programming Languages (11th Edition)
- Consider the following class definition: (8)class base{public:void setXYZ(int a, int b, int c);void setX(int a);int getX() const { return x; }void setY(int b);int getY() const { return y; }int mystryNum() { return (x * y - z * z); }void print() const;base() {}base(int a, int b, int c);protected:void setZ(int c) { z = c; }void secret();int z = 0;private:int x = 0;int y = 0;};a. Which member functions of the class base are protected?b. Which member functions of the class base are inline?c. Write the statements that derive the class myClass from classbase as a public inheritance.d. Determine which members of class base are private, protected,and public in class myClass.arrow_forwardExample Code Ch 09-4Given the following partial class definition:public class A1{public int x;private int y;protected int z;...}public class A2 extends A1{protected int a;private int b;...}public class A3 extends A2{private int q;...} 1. Refer to Example Code Ch 09-4: Which of the following is true with respect to A1, A2, and A3?a. A1 is a subclass of A2 and A2 is a subclass of A3b. A3 is a subclass of A2 and A2 is a subclass of A1c. A1 and A2 are both subclasses of A3d. A2 and A3 are both subclasses of A1e. A1, A2 and A3 are all subclasses of the class Aarrow_forwardExamine the following code and select the correct statements (choose all possibleoptions): class Bottle {Bottle() {}Bottle(WaterBottle w) {}}class WaterBottle extends Bottle {WaterBottle() { }WaterBottle(Bottle w) { } } a) The class Bottle defines two overloaded constructors.b) The class WaterBottle defines two overloaded constructors.c) The class compiles successfully—a base class can use reference variables of its derived class as method parameters.d) Bottle and WaterBottle cause syntax errors.e) The class compiles successfully - A derived class can use reference variables of its base class as method parameters.f) A base class can’t pass reference variables of its defined class, as method parameters in constructors.arrow_forward
- The BankAccount class described below is used to represent a personal savings account with a yearly interest rate, (represented as a percentage, e.g., a 7% rate is represented by .07). The interest is applied monthly, (i.e., at the end of each month 1/12 of the interest is deposited into the account). public class BankAccount { public BankAccount(double rate) public BankAccount(double initBal, double rate) public double getBalance() public double getIntRate() public void setIntRate(double rate) public void deposit(double amount) public void withdraw(double amount) public void addMonthsInterest() private double balance; private double intRate; } Suppose a bank offers to its special customers a new type of savings account, called a “Credit Account”, that allows the customer to withdraw extra money if needed, so that the account balance is allowed to be negative at some times. These accounts award interest at the end of every month, as long as the balance is positive. If the…arrow_forwardConsider the following declarations: class xClass{public:void func();void print() const ; xClass ();xClass (int, double); private:int u;double w;};Sample Output: Program 2 and assume that the following statement is in a user program: xClass x;a. How many constructors does class xClass have?b. Write the definition of the default constructor of the class xClass so that the private member variables are initialized to 0.c. Write the definition of the constructor of the class xClass so that the private member variables u and w are initialized to the values passed in the functions.arrow_forwardUse the following partial class definitions to answer the question: public class A1 { public int x; private int y; protected int z; } public class A2 extends A1 { protected int a; private int b; } public class A3 extends A2 { private int q; } Which of the following lists of instance data are accessible in A3? Group of answer choices x, y, z, a, b, q a, b, q a, q x, z, a, q x, a, qarrow_forward
- Kindly Give me (OOP) C++ codes for the following question. Question: Consider the following class definition:public class date { private int day; // from 1 to 31 private int month; // from 1 to 12 private int year; // from 2000 upwards public void advance (); // move to next day }; A) Implement a constructor that initializes new objects of date class to be set to the 1st of January 2000. B) Implement setters for day, month, and year. C) Implement the advance method, which moves to the next day, ensuring that all data members are updated appropriately.arrow_forwardHello, I am having trouble with this homework question for my c++ course. Implement a Rational Number class with the following specifications. Data members a) numerator and denominator Functions a) Constructors: 1) default constructor 2) single parameter constructor to create numerator/1 3) dual parameter constructor to create numerator/denominator 4) Use constructor delegation across all constructors. b) Accessors and Mutators for both data members. c) Static recursive GCD function using Euclid's algorithm. d) Static LCM function for two numbers. e) Reduce function simplify a rational number. This function modifies its calling object. f) Your program should work with the supplied driver program. Notes LCM (Least Common Multiple) This function returns the smallest multiple of a and b. Step 1: Multiply a and b to find a common multiple. Step 2: Divide the common multiple by the GCD of a and b. Step 3: Return the result of Step 2. Reduce: This function reduces a fraction to…arrow_forwardQ5: Consider the following code. [14]class A{protected:double x;public:A(){ cout<<"Constructor of Class A"<<endl; }void Display(){cout<<"Function Display of Class A"<<endl;}virtual void Print(){cout<<"Function Print of Class A";}virtual void Show()=0;}; class B:public A{protected:double y;public:B(){cout<<"Constructor of Class B"<<endl;}void Display(){cout<<"Function Display of Class B"<<endl;}void Show(){cout<<"Function Show of Class B"<<endl;}};class C:public A{public:C(){cout<<"Constructor of Class C"<<endl;}void Display(){cout<<"Function Display of Class C"<<endl;}};class D:public B{};void main(){Line 1: A *Ptr[3];Line 2: P[0]=new A;Line 3: Ptr[1]=new B;Line 4: Ptr[2]=new C;Line 5: Ptr[1]->Show();Line 6: Ptr[1]->Display();Line 7: Ptr[1]->Print();Line 8: Ptr[2]=new D;Line 9: Ptr[2]->Show();}a) List down the abstract and concrete classes?b) Find and correct the errors in the above…arrow_forward
- Question: 3Implement the design of the Doctor and Engineer class derived from Person class so that the following code generates the output below:class Person: def __init__(self, name, contact): self.name = name self.contact = contact def __str__(self): s = f"Name: {self.name}\nContact: {self.contact}" return s#Write your code hered = Doctor("Dr Strange", "4585632", "Neurosurgery", "DMC")d.add_patients("Dhaka Abdur Rahim", "Dhaka John Cena", "Narayanganj John Wick", "Comilla CM Punk")print("1.=========================================================")print(d)print("2.=========================================================")d.show_patient_list("Dhaka")print("3.=========================================================")d.show_patient_list("Rajshahi")print("4.=========================================================")d.add_patients("Narayanganj Naruto…arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. C++ Virtual Methods Create the following 3 classes: 1. AppWindow class, containing: - A protected instance of a rectangle class Rect defining the AppWindow's position (x,y) and size (w,h). (You may use the Rect class you developed in the previous lab. In main(), the width and height are assumed to be public and called "w" and "h".) - The following constructors to initialize the dimensions: AppWindow(); // initialize member rect's dimensions to 0AppWindow( float x, float y, float w, float h ); // initialize member rect's dimensions with the 4 floatsAppWindow( const Rect& r ); // initialize member rect's dimensions with r's dimensions - A method to retrieve the member rectangle: const Rect& get_rect(); - A virtual method called resize(). When this method is called, your implementation is supposed to change the dimensions of the internal rectangle of the window. virtual void resize( int w, int h ); 2.…arrow_forwardAssignment Question : #include <iostream> using namespace std; class Animal { protected: int length, height; public: void set_values (int l, int h) { length = l; height = h; } virtual int cage_size (void) =0; }; A. Based on the above class definition, provide the derived classes below that will override the function cage_size from the base class Animal: i.Elephant, cage_size = 1.5 x length x height ii.Giraffe, cage_size = 2.5 x length x height B. Write the complete main () function that will create the object Elephant and Giraffe. Insert their length and height to calculate their cage_size. Note: A virtual function is a member function which is declared within a base class and is expected to be re-defined (overridden) by a derived class.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr