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 25STQ
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
Can 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"
Do in c#
1. How can we write a parameter less Lambda expression?
a. Need to pass curly braces to denotes that there are no parameter on left side of the arrow.b. Pass empty set of parentheses on the left side of the arrow.c. In this particular case arrow is not required at all.d. No need to pass anything on the left side of the arrow.
2. Which of the following is NOT true about functional interface in Java?
a. It has multiple methods that needs to be implemented.b. Lambda expression implicitly implement the single method inside functional interface.c. If a lambda expression is provided then the method name should not be provided.d. It has only a single method that needs to be implemented.
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
- only in java not in java c++ 1. Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); 2. Implement the Shape interface for Rectangle, Circle and Triangle class. 3. Implement a class CalculateAreas that has a function that takes shape type array of objects and builds an array of (double values) values for each corresponding shapesarrow_forwardWrite the Talker interface, Animal abstract class, plus the Dog, Cat, Fish, and Radio classes for this Java Program. Talker.java - the interface Talker, which has just one void method called speak() Animal.java - the abstract class Animal, which stores an animal's name. (No abstract methods). It should contain 2 methods: a constructor with 1 argument (the name) a method getName() which returns the name. Dog.java - the class Dog, which extends Animal and implements Talker. It should contain 3 methods: a constructor with no arguments, giving the dog a default name of "Fido" a constructor with 1 argument (the name) a speak() method that prints "Woof" on the screen. Use @Override Cat.java - the class Cat, which extends Animal and implements Talker. It should contain just 2 methods: a constructor with 1 argument (the name) (no default name like dogs have) a speak() method that prints "Meow" on the screen. Use @Override Fish.java - the class Fish, which is an Animal that…arrow_forwardCreate 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)arrow_forward
- 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.arrow_forwardDo it in C# windows application form.arrow_forwardIn C++ Language using Functions and Pointers PROBLEM: Consider the elevator in the Faculty of Engineering (5 storey). Write a program which accepts the floor number where a passenger (student/faculty/other personnel) will ride the elevator. The passenger can then input the target destination floor. SPECIFICATIONS: Implement the class diagram below: Inside the main method, create an instance of the class Elevator. Use the goUp or goDown methods to generate the program display.Passenger can ride in any floor (1,2,3,4 or 5). Program will prompt the user with the target destination floor. After the user input: Program will display the floors which the elevator passes through, and finally the destination floor. Elevator will not move if the input for destination floor is the same as the present floor. Program will notify the user and then terminate. Program will also terminate if the input destination is not 1,2,3,4 or 5. You’re free to format the input/output display. Observe proper…arrow_forward
- Note: Write a Java Program in the given Picture.arrow_forwardCreate 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:…arrow_forwardCan we declare a class as Abstract without having any abstract method?arrow_forward
- We have a parking office class for an object-oriented parking management system using java Add (implement )a function to the Parking Office class to return a collection of customer ids (getCustomerIds) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getcustomerID function as mentioned above Explain the code you wrote with a few wordsarrow_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_forward1. Define an interface Measurable. It has a single abstract method: double getArea(); 2. Define an abstract class Shape which has two fields: type and name both of type Strin a. Provide constructor with a single input parameter: name. b. Provide accessor methods for both fields. C. Provide setter method for name. d. Provide toString() method that simply returns the "(type): (name)" e. Shape class implements Measurable interface without implementing its only abs method. 3.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT