Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8.4, Problem 26STQ
Program Plan Intro
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods. It is very similar to class, but it cannot be instantiated, rather it is implemented by other classes.
An interface needs to the follow certain conditions such as:
- • One cannot instantiate an interface.
- • Interfaces do not contain any constructors.
- • All methods present in the interface are abstracts.
- • An interface does not contain any instance field.
- • An interface cannot be extended by a class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Assume B is a subclass of A. Which of the statements about the following assignment is false?
A a = new B();
We can assign anything to variable a that has a subtype of B.
We can call on a any method defined in A.
We can call on a any method defined in B.
We can assign anything to variable a that has a subtype of A.
Can we have static methods in an Interface?
Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle with abstract methods getColor () and getBrand (). Now, create a concrete class Taxi with additional method setDriver (String name) that inherits both Wheel and Vehicle. (Note: Concrete classes don’t have any abstract method)
Chapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 8.1 - Prob. 1STQCh. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Can a derived class directly access by name a...Ch. 8.1 - Can a derived class directly invoke a private...Ch. 8.1 - Prob. 6STQCh. 8.1 - Suppose s is an object of the class Student. Base...Ch. 8.2 - Give a complete definition of a class called...Ch. 8.2 - Add a constructor to the class Student that sets...Ch. 8.2 - Rewrite the definition of the method writeoutput...
Ch. 8.2 - Rewrite the definition of the method reset for the...Ch. 8.2 - Can an object be referenced by variables of...Ch. 8.2 - What is the type or types of the variable(s) that...Ch. 8.2 - Prob. 14STQCh. 8.2 - Prob. 15STQCh. 8.2 - Consider the code below, which was discussed in...Ch. 8.2 - Prob. 17STQCh. 8.3 - Prob. 18STQCh. 8.3 - Prob. 19STQCh. 8.3 - Is overloading a method name an example of...Ch. 8.3 - In the following code, will the two invocations of...Ch. 8.3 - In the following code, which definition of...Ch. 8.4 - Prob. 23STQCh. 8.4 - Prob. 24STQCh. 8.4 - Prob. 25STQCh. 8.4 - Prob. 26STQCh. 8.4 - Prob. 27STQCh. 8.4 - Prob. 28STQCh. 8.4 - Are the two definitions of the constructors given...Ch. 8.4 - The private method skipSpaces appears in the...Ch. 8.4 - Describe the implementation of the method drawHere...Ch. 8.4 - Is the following valid if ShapeBaSe is defined as...Ch. 8.4 - Prob. 33STQCh. 8.5 - Prob. 34STQCh. 8.5 - What is an advantage of having the main...Ch. 8.5 - What Java construct allows us to define and...Ch. 8 - Consider a program that will keep track of the...Ch. 8 - Implement your base class for the hierarchy from...Ch. 8 - Draw a hierarchy for the components you might find...Ch. 8 - Suppose we want to implement a drawing program...Ch. 8 - Create a class Square derived from DrawableShape,...Ch. 8 - Create a class SchoolKid that is the base class...Ch. 8 - Derive a class ExaggeratingKid from SchoolKid, as...Ch. 8 - Create an abstract class PayCalculator that has an...Ch. 8 - Derive a class RegularPay from PayCalculator, as...Ch. 8 - Create an abstract class DiscountPolicy. It should...Ch. 8 - Derive a class BulkDiscount from DiscountPolicy,...Ch. 8 - Derive a class BuyNItemsGetOneFree from...Ch. 8 - Prob. 13ECh. 8 - Prob. 14ECh. 8 - Create an interface MessageEncoder that has a...Ch. 8 - Create a class SubstitutionCipher that implements...Ch. 8 - Create a class ShuffleCipher that implements the...Ch. 8 - Define a class named Employee whose objects are...Ch. 8 - Define a class named Doctor whose objects are...Ch. 8 - Create a base class called Vehicle that has the...Ch. 8 - Create a new class called Dog that is derived from...Ch. 8 - Define a class called Diamond that is derived from...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PPCh. 8 - Prob. 4PPCh. 8 - Create an interface MessageDecoder that has a...Ch. 8 - For this Programming Project, start with...Ch. 8 - Modify the Student class in Listing 8.2 so that it...Ch. 8 - Create a JavaFX application that uses a TextField...Ch. 8 - Prob. 10PP
Knowledge Booster
Similar questions
- Suppose the class SportsCar is a derived class of a class Automobile,and suppose also that the class Automobile has public methods namedaccelerate and addGas. Will an object of the class SportsCar havemethods named accelerate and addGas? If so, do these methods haveto perform the exact same actions in the class SportsCar as in the classAutomobile?arrow_forwardCan you implement the Derived Class Parameterized constructor? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. Implement the constructor Dell(String name) of the Derived Class Dell which takes a string, name. We have already implemented the Base Class Laptop with the member function getName() and a parameterized constructor. Input# Laptop name is being passed through the parameterized constructor. Output# getName() method is returing Laptop name. Sample Input# Dell dell = new Dell("Dell Inspiron"); Sample Output# "Dell Inspiron"arrow_forwardWrite a complete program for the description given below. Consider a Billing class that implements an interface Payable having a method getTotalPayment Amount(). Besides this, you have a Doctor class with private instance variables (docID, docName, and docFee) and a public getDoc() method, Patient class with private instance variables (pName, pID. pDisease), Medicine class with private instance variables (medID, medName, medQty, medPrice), and Medical Test class with private instance variables (testID, testName, testPrice). Each of these classes has the toString() method to display the information of its object. The Billing class is having "Has A" relationship with the other four classes (Doctor, Patient, Medicine, and MedicalTest) mentioned above. The getPayment Amount() method of Billing class returns the total billing amount that includes doc fee, medicine cost, and medical test fee that a patient has to pay. After implementing these classes, you are required to do the following in…arrow_forward
- B elow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forwardB elow for each class you find a UML and description of the public interface. Implementing the public interface as described is madatory. There's freedom on how to implement these classes.The private properties and private methods are under your control.. There are multiple ways of implementing all these classes. Feel free to add private properties and methods. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. It's best to develop the driver as the class is being written. Check each section to see if there are added additional requirements for the driver. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate…arrow_forwardGiven a class student that represents names and grades of a class: 1. How would we implement the Comparable interface in our class so we can compare the scores of individual students? Write the complete Class Header implementing this interface. 2. Write the complete Method Header for the Student class's compareTo method. You do not need to write the body of the method.arrow_forward
- This example asks you to write an interface. Then define three classes that implement this interface. 1) Create an interface Discount Policy. It should have a single abstract method called computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and item Cost. This interface has no other method. 2) Define a class Bulk Discount that implements the interface Discount Policy, as de- scribed above. It should have a constructor that has two parameters, minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more than minimum, the discount is percent percent. 3) Define another class Buy NItemsGetOneFree that implements Discount Policy as de- scribed in part 1. The class should have a constructor that has a single parameter n. In addition, the class should define the method computeDiscount so that every nth item is free. For ex- ample, the following table…arrow_forwardUsing JAVA Language Consider a Billing class that implements an interface Payable having a method getTotalPaymentAmount(). Besides this, you have a Doctor class with private instance variables (docID, docName, and docFee) and a public getDoc() method, Patient class with private instance variables (pName, pID, pDisease), Medicine class with private instance variables (medID, medName, medQty, medPrice), and MedicalTest class with private instance variables (testID, testName, testPrice). Each of these classes has the toString() method to display the information of its object. The Billing class is having "Has A" relationship with the other four classes (Doctor, Patient, Medicine, and MedicalTest) mentioned above. The getPaymentAmount() method of Billing class returns the total billing amount that includes doc fee, medicine cost, and medical test fee that a patient has to pay. After implementing these classes, you are required to do the following in the driver class: Create an ArrayList of…arrow_forwardCreate a base class with an abstract print( ) method that is overridden in a derived class. The overridden version of the method prints the value of an int variable defined in the derived class. At the point of definition of this variable, give it a nonzero value. In the base-class constructor, call this method. In main( ), create an object of the derived type, and then call its print( ) method. Explain the results. (JAVA)arrow_forward
- Do in c#arrow_forwardlanguage is c++ sample output included with user input in boldarrow_forwardin c++ 3. Develop additional classes for Cat, Horse, and GuineaPig overriding the move() and speak() methods. (If you didn’t know, guinea pigs go “wheep wheepLinks to an external site.”). Make sure to also define a constructor and destructor for each of these classes, and that when you run your program, you can also see that the correct constructors and destructors are being called. Recall that a derived class will always call the parents constructors and destructors, so if you see this behavior, that is okay. Just make sure you are also calling the derived class’ constructors and destructors. Test with the modified main: int main (){Mammal* theArray[5];Mammal* ptr;int choice;for (int i = 0; i < 5; i++){cout << "(1)dog (2)cat (3)horse (4)guinea pig: ";cin >> choice;switch (choice){case 1: ptr = new Dog;break;case 2: ptr = new Cat;break;case 3: ptr = new Horse;break;case 4: ptr = new GuineaPig;break;default: ptr = new Mammal;break;}theArray[i] = ptr;}// Iterate through…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,