Question
Q1. Define an interface with its syntax. Give differences between an abstract class and an interface. Q2. Consider the following problem description and write the
Q1. Define an interface with its syntax. Give differences between an abstract class and an interface.
Q2. Consider the following problem description and write the Java code.
(a) Create two interfaces Interest and Balance.
(b) Define in each interface one method used in order to get the rate of interest and the balance of the bank account implementing them respectively.
(c) A BankAccount class that implements these two interfaces.
Note: use the appropriate instance variables, constructors, and methods.
(d). Call both the methods in the main() method.
Q3.
(a) Define Inheritance. Give an Example.
(b) Also give the structure/definition of the base class from your example and a derived class stating the fields and methods of both the classes and the methods overridden in the base class. You may declare Abstract class as well if required.
Q4.
Consider the following code snippet:
public class Motorcycle extends Vehicle
{
. . .
public Motorcycle (int numberAxles)
{
super(numberAxles);
}
}
What does the super keyword do?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started