INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Object Oriented Programming
INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Interfaces.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis 1.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
More about classes and objects Classes in Visual Basic.NET.
1 Anonymous Classes A local class is a class that is defined in a block. This could be a method body, a constructor, a local block, a static initializer.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
UML Class Diagram: class Rectangle
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Lecture 3 Casting Abstract Classes and Methods Interfaces.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Computer Science [3] Java Programming II - Laboratory Course Lab 3-1: Creating and Using Interfaces Exception Faculty of Engineering & IT Software Engineering.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Modern Programming Tools And Techniques-I
Topic: Classes and Objects
Web Design & Development Lecture 9
Chapter 15 Abstract Classes and Interfaces
Inheritance ITI1121 Nour El Kadri.
Inheritance-Basics.
Final and Abstract Classes
Inheritance and Polymorphism
Interface.
Chapter 11: Inheritance and Polymorphism
UML Class Diagram: class Rectangle
Modern Programming Tools And Techniques-I Inheritance
OOP’S Concepts in C#.Net
More inheritance, Abstract Classes and Interfaces
Interface.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Java Programming Language
Sampath Kumar S Assistant Professor, SECE
Interfaces.
OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS
METHOD OVERRIDING in JAVA
Inheritance Inheritance is a fundamental Object Oriented concept
Chapter 14 Abstract Classes and Interfaces
An Example of Inheritance
Chapter 11 Inheritance and Polymorphism Part 1
Final and Abstract Classes
Topics OOP Review Inheritance Review Abstract Classes
Presentation transcript:

INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh

ABSTRACT CLASS AND METHODS Abstract methods are those methods which are to be redefined in sub class , thus making overriding compulsary. Example: abstract class shape { …………………. abstract void draw(); // prototype ………………… } .

Rules We cannot use abstract classes to instantiate objects directly. The abstract method of an abstract class must be defined in its sub class. We cannot declare abstract constructor or abstract methods.

INTERFACES Multiple inheritance is not possible in java programming language but we can achieve the feature through interfaces. An interface is basically a kind of class. Like class it contain method and variables with the difference that an interface can contain only abstract method and abstract classes. They cannot contain any code. This is the responsibility of the class that implements an interface to define the code for implementation of these methods.

Difference between class and interface. 1.The member of a class can be constant or variables. 2.The class definitions can contain code for each of its methods. 3.It can be instainted by declaring objects. 4.It can use various access specifiers like public , private or protected. 1.The members of an interface are always declared as constant. 2.The methods in an interface are abstract in nature. 3.It cannot be used to declare objects, It can be only inherit by class. 4. It can only use the public access specify.

Defining an Interface Here interface is a keyword and interface name is any valid java variable . Syntax: Interface interfaceName { Variable Declaration; Methods Declaration; }

Extending Interfaces Like classes, Interfaces can also be extended. That is an interface can be sub interfaced from other interfaces by using the keyword extends. Syntax: Interface name1 extends name2 { Body of name 2 }

Implementing the interfaces Interfaces are used as “superclasses” whose properties are inherited by classes by using the keyword implements. Syntax: Class classname impements interfacename { body of class }

Example Interface Area { final static float pi=3.14f; int compute(int x, int y); } class Rectangle implements Area public float compute(float x, float y) Return(x*y); }}

Class circle implements Area { public float compute(float x, float y) return(pi*x*x); }

class test { public static void main(String arg[]) Rectangle r1= new Rectangle(); circle c1= new circle(); Area a; a=r1; System.out.println(“Area of a rectangle=“+ a.compute(10,20)); a=c1; System.out.println(“Area of a square=“+ a.compute(10,0)); }

Program to show the multiple inheritance. interface a // an interface is created { Int a=10; //variable declared } Interface b String str =new string (“hello”); Interface c extends a, b // interface c inherit a and b interface OUTPUT { 10 Void show(); Hello Class test implements c Public void show() System .out. Println (“value of a “+ a) ; System .out. println (“value of string:” + str) ; } } Class test Public static void main( String args[]) test t1 = new test () ; t1. show () ; } }

THANK YOU