Add a constructor for Animal class shown. The constructor should pass in a string parameter named "sound". 1 using System; 2 3 public class Animal 4 { 50 public string Sound { get; set; } public void Speak() { Console.Wiriteline("The dog says " + Sound); 8. 9. 10 11 } 12 13 public class Program 14 { 15 public static void Main() 16 { 17 18 19 }
Q: An encapsulation violation occurs when private information that should not be changed by external…
A: The given feature Encapsulation is one of the most favorite features of Object-oriented programming…
Q: (Java) Make the 2 following classes: Employee.java EmployeeTest.java Copy and paste the below…
A: In Java, the most searching program is of employee details. An employee is an entity that can have…
Q: Write a class named Person with data attributes for a person’s name, address, and telephone number.…
A: Given:- Write a class named Person with data attributes for a person’s name, address, and telephone…
Q: Given the following super class and subclasses: public abstract class ThemePark String name: //…
A: Default constructors are the constructors that has no parameters whereas normal constructors are the…
Q: Write a Java class Person for dealing with persons. Your class must have the following features:…
A: As per the requirement person class is developed. Note: As per our guidelines we are suppose to…
Q: 4. Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle…
A: Solution: Given,
Q: The BankAccount class models changes to the balance of a person's savings account. public class…
A: Below are the answers with code and explanation respectively:
Q: Write a class named Person with data attributes for a person’s name, address, and telephone number.…
A: Python program for the above problem is given below:-
Q: Consider the classes shown below: public class Parent { private int value = 100; public int…
A: Inheritance is a mechanism in which one object acquires all the properties and behaviors of a parent…
Q: Write a Java class Person for dealing with persons. Your class must have the following features:…
A: class Person{ long person_id; String name,gender; //default constructor Person(){…
Q: Consider the following class definition. public class Liquid { private double boilingPoint; private…
A: Here is the explanation about the behavior of the program:
Q: Using the concept of classes in object-oriented programming Write java project for Medical Center…
A: Code: import java.io.*; import java.util.*; import java.util.Calendar; /* Hospital Management System…
Q: Implement the following classes / abstract classes below. Monster abstract class which has health…
A: public class Main { public static void main (String[] args) { //create 3 instances and…
Q: Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an…
A: Programming instructions: Create a class Employee. In the Employee class, create the instance…
Q: Add the following new constructor in the BMI class:/** Construct a BMI with the specified name, age,…
A: Program code: File name: BMICalculation.java //import the required packages import…
Q: hispe Define a public class Whisperer that provides a single class method named vhisper.whisper…
A: Note: Since you have not provided the language to write the code so I am using java language to…
Q: (Java) 3. public class person{ 4. private double salary; 5. public person(){ 6. salary =…
A: Non-parameterized Constructor/Default Constructor: Non-parameterized constructors are those that…
Q: thod
A: Create classes Name, DebitCard and TestClass as per the requirements of the question. In the…
Q: Use Java. Given main() and the Instrument class, define a derived class, StringInstrument, for…
A: StringInstrument.java public class StringInstrument extends Instrument { private int…
Q: Write a class HouseBuilder with private class members as houseArea(double, e.g. 20 square feet),…
A: abstract class HouseBuilder{ protected double houseArea; protected String houseLocation;…
Q: Code is in Java find the error in the following class definition: public class MyClass {…
A: public void MyClass(int a, double b) The Above Line Is Incorrect. There Won't be any Return Type…
Q: public class Ice extends Fire { public void method1() { System.out.print("Ice 1 "); public class…
A: Output of the given program is given below:-
Q: Include the following methods: - A constructor with 3 parameters. Initialize the 3 member variables…
A: Name.java class: public class Name { String firstname,middlename,lastname; public Name(String…
Q: Consider the following class definitions public class SampleClass{ public String greet() {return…
A: In the given below code public class SubClass extends SampleClass{ public string greet() {return…
Q: 2. Consider the following class definitions: public class BClass private int x; public void set(int…
A: Lets see the solution in the next steps
Q: Write a class HouseBuilder with private class members as houseArea(double, e.g. 20 square feet),…
A: using static System.Console; namespace ConsoleApp1 public class HouseBuilder { private double…
Q: Java always provides a default constructor. That is, a constructor that can be caller with no…
A: We have to explain whether this statement is true or false. Java always provides a default…
Q: Consider the following class definition: public class AClass { private int u; private int v; public…
A: Inheritance- Inheritance is one of the feature of Object Oriented Programming.…
Q: Modify the given codes to remove the compilation errors. 1. public interface Carnivore {…
A: Answer: Ans-1: The code will not compile and it will be given you the two compile-time errors…
Q: What will be the output of the following code? abstract class X { int b; abstract void print(); }…
A: abstract class X{ int b; abstract void print();}class Y extends X{ int a; void print()…
Q: Given the following code: } public class Foo { public void barl () { public abstract void bar2 ();…
A: abstract method Only applicable in an abstract class, an abstract method lacks a body. The subclass…
Q: What is the output of the following code? public interface yourInterface { int x = 10, y = 20; void…
A: Interface: Interface in java is abstract type. The methods of interface are implemented by classes.…
Q: public abstract class Plant { } public abstract void breathe (); Consider the class shown above.…
A: Solution- Before solving this problem first need to under the concept of the abstract class.…
Q: public abstract class Landmark { public abstract int countVisitors(); } Consider the class shown…
A: Data Abstraction is an OOP concept that hides the background details. It shows only those…
Q: Consider the following class definition and answer the following questions: public class MyClass {…
A: We need to find the output of the given Java code. MyClass object1=new MyClass(12,15); //This sets…
Q: Write a java program Write a class named Employee with name and salary as private data fields. Add…
A: The main objective of the program is to create three java files. Employee.java Manager.java…
Q: Fill in the blanks for the method signature of a Deep Copy constructor for the Plant class. public…
A: Please find the answer below
Q: Java: Derive the class ExtClock from the class Clock by adding a data member to store the time zone.…
A: Inheritance is a feature of java object-oriented programming. The property of acquiring the parent…
Q: What is the output of the following code? public interface yourInterface { int x = 10; %3D int y =…
A: Operators are the fundamental building blocks of all programming languages. Java, too, has a variety…
Q: Solve the programming exercise P9.8 on Page 490 on the book. Implement a superclass Person. Make two…
A: // Screenshot of the code & output
Q: An encapsulation violation occurs when private information that should not be changed by external…
A: Encapsulation in object-oriented programming usually known as binding the data altogether with the…
Q: Create a base class, cell phone and derive a class smartphone from it. In cell phone, create…
A: Abstract classes are parent classes or base classes. Abstract classes contain the common…
Q: b) Following program contains two different kind of errors. Identify and explain those errors?…
A: Here we have abstract class A which contains two methods private abstract method m1() and final…
Q: public abstract class Building { } public abstract String increaseSize(); Consider the class shown…
A: The following question is in Java Programming Language and Uses the Concept of Java Extends.
Q: Write a class Battery that models a rechargeable battery. A battery has a constructor
A: public class BatteryTester{ public static void main (String[] args) { Battery battery=new…
Q: Implement all the classes using Java programming language from the given UML Class diagram.
A: public class Shape { //declaring instance variables private String color; private boolean filled;…
Q: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
A: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
Q: class Employee { String name; double salary; public Employee() { }
A: The class is EMPLOYEE. It has got a constructor of same name. Attributes are: 1. name of type…
Q: Please define two interface Auto and Sprinkler, and three classes Car, Truck and FireTruck. Car and…
A: Code: interface Auto{ public abstract void move(); public abstract void stop(); public…
Q: 1- public class Student { 2 3 public abstract double calcScore(); 4 5 } Which of the following is…
A: The given code is a java code snippet where a Student class is created. The student class has method…
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- Write a java program in which Animal:Create a class Animal and Add a protected data member named id of integer type.• Add get/set methods for id data member in Animal class with public access. Also provide default constructor this should initialize id to 0.• Also provide parameterized constructor and toString method.• Add an abstract method tellAboutSelf method to Animal class with public access• Add another abstract method speak method to Animal class.Reptile, Bird, MammalNext create the three child classes which extends form Animal class.• Add a default constructor to each of the above created class. The constructor should initialize the id data member id, Reptile, Bird and Mammal, to 1, 2 and 3 respectively also it display a message “(class Name)’s default constructor”. E.g. for Bird it says “Bird’s default constructor”.• Add a parameterized constructor to each of the above created class. The constructor should initialize the id data member, Reptile, Bird and Mammal, to the…Examine 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.Question :- Add a statement to the classA to test whether myChar is accessible. public class ClassB { public int x = 1; int y = 2; private int z =3; } public class ClassA { public static void main(String[] args) { ClassB cb = new ClassB(); // System.out.print(cb.x); /* 1 */ // System.out.print(cb.y); /* 2 */ // System.out.print(cb.z); /* 3 */ } }
- Create a class Animal Create 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 makes Sound () with the implementation printing out a generic animal sound. Next, override (add) the makes Sound() 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 makeSound method called will be: cat -> from Cat class, dog-> from Dog class, bearded Dragon -> from Animal class ) EC:…Consider the following class definitions public class SampleClass{ public String greet() {return "Greetings";} } public class SubClass extends SampleClass{ public string greet() {return "Hello";} } public class AnotherClass{ public String greet() {return "Hi";} } What can be said about the following code fragment? public class Driver { public static void main(String[] args){ Object p =new SampleClass(); System.out.println((AnotherClass).p),greet()); } } a. The above code compiles but causes runtime error. b. The above code has no issues. It compiles and runs. c. The above code causes compiler error.The Essay class has a default constructor, a constructor with two parameters, and a constructor with three parameters. Declare the following objects: essay1 with no arguments essay2 with essayTitle and essayAuthor as arguments essay3 with essayTitle, essayAuthor, and essayYear as arguments Ex: If the input is Painting Cole 1919, then the output is: Essay: Undefined, Unspecified, 0 Essay: Painting, Cole, 0 Essay: Painting, Cole, 1919 Archive.java public class Archive { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); StringessayTitle; StringessayAuthor; intessayYear; essayTitle=scnr.next(); essayAuthor=scnr.next(); essayYear=scnr.nextInt(); /* Your code goes here */ essay1.print(); essay2.print(); essay3.print(); } } Essay.java public class Essay { private String title; private String author; private int year; public Essay() { // Default constructor title = "Undefined"; author = "Unspecified"; year = 0; }…
- Define a class named Doctor whose objects are records for a clinic’s doctors. Derive this class from the class Person given in Listing 8.1. A Doctor record has the doctor’s name—defined in the class Person—a specialty as a string (for example Pediatrician, Obstetrician, General Practitioner, and so on), and an office-visit fee (use the type double). Give your class a reasonable complement of constructors and accessor methods, and an equals method as well. Write a driver program to test all yourmethods.**Python code** Write a class definition line and a one line docstring for the class Dog. Write an __init__ method for the class Dog that gives each dog its own name and breed. Test this on a successful creation of a Dog object.>>> import dog>>> sugar = dog.Dog('Sugar', 'border collie')>>> sugar.name'Sugar'>>> sugar.breed'border collie'public class Father { public String name; public int age; // customer name Father(){ name=”Hassan”; age=50;} public void display(){ System.out.println(“Name:”+name); System.out.println(“Age:”+age); } } 1. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. 2. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). 3. Define a method display () in class Child, execute the display ( ) method in superclass using the keyword super. Method display ( ) in class Child should print the information of name, age and location 4. Create other class named Main for the main method and create 2 objects for the 2 classes (Father and Child). Then execute the display ( ) method for Father and Child. Example of the output as in Figure 4: Father's info: Name: Josh Age: 50 Child's info: Name: Christy Age: 20 Location:…
- Assignment: Write the class XXXX_Worker with constructors, accessors, mutuators, and a toString method. A Worker has a Worker Name and Number. Write the class XXXX_ProductionWorker which is a subclass of Worker. The production worker has a shift number (values: 1 or 2) and an Hourly pay rate. A shift number of 1 means the day shift and 2 means the night shift. Write the class XXXX_ShiftSupervisor which is a subclass of Worker. The shift supervisor is a salaried worker who supervises a shift. The shift supervisor has a yearly bonus field. The yearly bonus is earned at year end based on performance. Write a class, XXXX_TestWorker, which does the following: Creates one Shift Supervisor object from information entered by the user. Creates an Array of Production Workers that can hold 3 objects. Itcreates3ProductionWorkerobjectsfrominformationenteredbytheuser Prints the information about each object in the format shown below using the toString methods of the…In this exercise, you have to calculate the student's total marks using the concept of Classes Problem Statement# Write a Java class called Student with ● private fields: ○ name(String type) ○ mark1 and mark2 (double type) And methods: ● getMarks(int markNumber), a method which should return mark1 if markNumber equals 1 and mark2 otherwise. ● calcTotal() method should take the two marks entered and return their sum. Also define two constructors: ● A default constructor that takes no parameters and initializes the values to zeros and null. ● A constructor that takes the three variables and sets them as the values of the appropriate fields. Input# Name of the student and the marks obtained in the first and second tests Output# Sum of both marks Sample Input# Student student = new Student("Jack", 60, 70); Sample Output# getMarks(1) => 60 getMarks(2) => 70 calcTotal() => 130.0 Part of solution class Student { // Define private fields here public Student() { // Write…Consider the following classes. public class Base { public Base() { System.out.print("Base" + " "); } } public class Derived extends Base { public Derived() { System.out.print("Derived" + " "); } } Assume that the following statement appears in another class. Derived d1 = new Derived(); What is printed as a result of executing the statement? A) Nothing is printed because the statement is a variable declaration. B) Base C) Derived D) Base Derived E) Derived Base