a)
Abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstract.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Given code:
//interface declaration
interface A
{
//declaration of function
void print() { };
}
b)
Abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstract.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Given code:
//interface declaration
abstract interface A
{
//declaration of function
abstract void print() { };
}
c)
Abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstract.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Given code:
//interface declaration
abstract interface A
{
//declaration of function
print() { };
}
d)
Abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstract.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Given code:
//interface declaration
interface A
{
//declaration of function
Void print();
}
e)
Abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstract.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Given code:
//interface declaration
interface A
{
//declaration of function
default void print() { }
}
f)
Abstract class:
An abstract class is a class which may or may not include abstract methods and cannot be instantiated but rather can be sub classed.
Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstract.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Given code:
//interface declaration
interface A
{
//declaration of static function
static int get
{
//return value
return 0;
}
//Close interface
}
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
- In this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. Provide Javadoc. Cylinder.java /*** Models a Cylinder*/public class Cylinder {private double radius;private double height; /*** Constructor for objects of class Cylinder* @param radius the radius of the Cylinder* @param height the height of this Cylinder*/public Cylinder(double radius, double height){this.radius = radius;this.height = height;}/*** Gets the radius of this…arrow_forwardI have provided you with 3 interfaces (HasLegs, HasWings, and BreathesUnderwater) and a Tester class. I want you to create 6 new classes: • 2 that implement HasLegs • 2 that implement HasWings • 2 that implement BreathesUnderwater For each of the classes, you will have to implement the methods that the interface dictates. In addition, override toString so that it prints out a simple message describing what the object is. See the example output of my implementation below for an idea how to do that. The Tester class creates 3 ArrayLists, one for each interface. It also loops through each ArrayList and prints out its contents using toString and the interface methods. In between those two chunks of code, you’ll see a //TODO: comment. It is there that I want you to create one object for each of the 6 classes you created and add that object to the appropriate ArrayList. Once you have done all that, you should be able to run your program and see output like the following: I am a table. I have…arrow_forward“Reverse - engineer” the code to produce an Object Diagram for the Producer and the Consumer classes found in the lower portion of the code. (Ignore the CandP class, it is just the staging for the application.) Using your common sense describe how you could improve the efficiency of this process in a few sentences.arrow_forward
- Which of the following cases is most like the adapter pattern? A. If you have an interface called Duck, and have many ducks that implement the duck interface. All of these ducks must have the behaviour “quack” but for some ducks, like a Mallard, this must result in a quack, where for a rubber duck it must result in a squeak. We decide to delegate the quack method to another interface, which can be implemented either in a concrete class that returns a quack or a concrete class that returns a squeak. B. None of these are like the adapter pattern. C. We have a large collection of Ducks. We want to look at them one by one and hear them quack. We write a piece of code that iterates through them all, and as we encounter each one, we have it invoke the quack method. D. If we have an interface called Duck. We need to give an object to a user that can quack like a duck. All we have is Turkeys. We create a special class that implements the duck interface, and to implement the quack…arrow_forwardplease use java to answer the following questionarrow_forwardUsing JAVA code: Please make a GUI that will convert infix to postfix expression. In the interface, please show also the process of the conversion (line by line).arrow_forward
- Your task is to develop a standard calculator in Java using BlueJ. Your implementation should use only following three packages: AWT, Swing and Util.Please implement the entire calculator within a single class. The GUI and the internal calculation logics should be separated under different methods. You may also choose to separate different parts of your code using sub-classes. This is what i should look like Please implement a GUI following the exact same layout as depicted in Fig. 1. In particular, the GUI should have the following components. • A display screen. The screen is to display the user inputs and the calculation outputs. The screen will display a digit “0” after the calculator is initialised. • A four-by-four grid with a total of 16 buttons. Among the 16 buttons, 10 of them correspond to the 10 digits, namely, 0, 1, 2, …, 9; four of them correspond to the four basic calculation operators, namely, addition (+), subtraction (-), multiplication (×) and division (÷); one is the…arrow_forwardgive me a example of this please i am confusedarrow_forward2. Write an interface for Tossable. We will say that every Tossable item has a way to toss it and we want to be able to give its color. A Tossable item by default is to throw an assist toss to another player.arrow_forward
- object-oreinted programming. need the full code together with the comments.arrow_forwardUsing this link: https://docs.oracle.com/javase/tutorial/java/concepts/interface.html and https://docs.oracle.com/javase/tutorial/java/concepts/class.html Create in Java: An interface named bicycle as described in the section: What is an interface? Add a new method for the interface bicycle: ring the bell with a parameter indicating how many time. Pick a bicycle brand and create a new class of bicycles for that brand, as described in the sections What is an interface? and What is a Class? For the new method implementation, write in the console "Clang! Clang!..." for how many times the parameter indicates. Create another class, with a main method, in which you will take a trip aroound your house, changing your bicycle attributes, starting and ending from a complete stop, and ringing the bell once at start and twice at the end. Use as inspiration the method in What is a Class? Your trip must have at least 5 different parts in which you change your bicycle…arrow_forwardWrite a java code that create the above shown interface which permits to simulate a reservation of a house worker. The frame size is 400*250. Use the necessary layout managers to arrange the components.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education