CS计算机代考程序代写 Java OOP_inJava_19T3

OOP_inJava_19T3

COMP2511

Object Oriented Programming (OOP)
in Java

Prepared by
Dr. Ashesh Mahidadia

OOP in Java

v Object Oriented Programming (OOP)

v Inheritance in OOP

v Introduction to Classes and Objects

v Subclasses and Inheritance

v Abstract Classes

v Single Inheritance versus Multiple Inheritance

v Interfaces

v Method Forwarding (Has-a relationship)

v Method Overriding (Polymorphism)

v Method Overloading

v Constructors

COMP2511: OOP in Java 2

Ashesh Mahidadia

Interfaces in Java

v Interfaces are like abstract classes, but with few important differences.

v All the methods defined within an interface are implicitly abstract. (We don’t need to
use abstract keyword, however, to improve clarity one can use abstract keyword).

v Variables declared in an interface must be static and final, that means,
they must be constants.

v Just like a class extends its superclass, it also can optionally implements an interface.

v In order to implement an interface, a class must first declare the interface in an
implements clause, and then it must provide an implementation for all of the abstract
methods of the interface.

v A class can “implements” more than one interfaces.

v More discussions on “interfaces” later in the course.

COMP2511: OOP in Java 25

Interfaces in Java: Example

COMP2511: OOP in Java 26

Using Interfaces: Example

v When a class implements an
interface, instance of that class can
also be assigned to variables of the
interface type.

COMP2511: OOP in Java 27

Implementing Multiple Interfaces

COMP2511: OOP in Java
28

A class can implements more than one interfaces. For example,

Extending Interfaces

v Interfaces can have sub-interfaces, just like classes can have subclasses.
v A sub-interface inherits all the abstract methods and constants of its super-interface,

and may define new abstract methods and constants.
v Interfaces can extend more than one interface at a time. For example,

COMP2511: OOP in Java 29