Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Study Notes for JAVA

Rating
-
Sold
-
Pages
2
Uploaded on
28-02-2022
Written in
2021/2022

Study Notes for JAVA

Institution
Course

Content preview

Chapter 10: Interfaces: Multiple Inheritance
10.1 Introduction
 Java provides an alternative approach to handle multiple inheritance known as
“Interfaces”
 Although a Java class cannot be a subclass of more than one superclass, it can
implement more than one interface, thereby enabling us to create classes that build upon
other classes without the problem created by multiple inheritance.
10.2 Defining Interfaces
 An interface is basically a kind of class.
 Interfaces contain methods and variables.
 Interfaces define only abstract methods and final fields.
 Interfaces do not specify any code to implement these methods and data fields contain
only constants.
 The general form of an interface definition is:
interface InterfaceName
{
Variables declaration;
Methods declaration;
}
o interface is the key word and InterfaceName is a valid variable.
 Variables are declared as follows:
static final type VariableName = Value;
o All variables are declared as constants.
 Method declaration is as follows:
return-type methodName (parameter-list);
 Eg:
interface Item
{
static final int code = 1001;
static final String name = “Fan”;
void display();
}
10.3 Extending Interfaces
 Interfaces can be extended
 An interface can be subinterfaced from other interfaces.
 The new subinterface will inherit all the members of the superinterface.
 Can be achieved using the keyword “extends”
 The general form is:
interface name2 extends name1
{
Body of name2;
}
 While interfaces are allowed to extend to other interfaces, subinterfaces cannot defines
the methods declared in the superinterfaces.
 When an interface extends 2 or more interfaces, they are separated by commas.
 An interface cannot extend classes
10.4 Implementing Interfaces
 Interfaces are used as “superclasses” whose properties are inherited by classes.

Connected book

Written for

Institution
Course

Document information

Uploaded on
February 28, 2022
Number of pages
2
Written in
2021/2022
Type
Class notes
Professor(s)
Mrs. prabitha
Contains
First 10 chapters covered

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sinithomas

Also available in package deal

Get to know the seller

Seller avatar
sinithomas Study Notes
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions