Interface.

Slides:



Advertisements
Similar presentations
Abstract Class and Interface
Advertisements

Object Oriented Programming
J A V A SHASHI BHUSHAN. MAIN ISSUES Object Oriented Concepts Examples FAQs.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
04 - Abstract Classes and Interfaces. 2 © S. Uchitel, 2004 Abstract Classes Unlike classes, these cannot be instantiated. Unlike classes, these cannot.
Interfaces.
UFCE3T-15-M Programming part 1 UFCE3T-15-M Object-oriented Design and Programming Block2: Inheritance, Polymorphism, Abstract Classes and Interfaces Jin.
UML Class Diagram: class Rectangle
Chapter 10: Inheritance and Polymorphism
Abstract Classes b b An abstract class is a placeholder in a class hierarchy that represents a generic concept b b An abstract class cannot be instantiated.
Multiple Choice Solutions True/False a c b e d   T F.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
Objects and Classes Mostafa Abdallah
Inheritance CSCE 190 – Java Instructor: Joel Gompert Mon, August 2, 2004.
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.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
CSE 143 Lecture 20 Abstract classes. 2 Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
Interfaces and Polymorphism CS 162 (Summer 2009).
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
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.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
1 / 41 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 5 Programming Fundamentals using Java 1.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
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.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Multiple inheritance Composition Interfaces Polymorphism Inheritance in Java (part 2)
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
Web Design & Development Lecture 9
Chapter 15 Abstract Classes and Interfaces
Interfaces.
Inheritance-Basics.
Inheritance and Polymorphism
Chapter 11: Inheritance and Polymorphism
Agenda Warmup AP Exam Review: Litvin A2
UML Class Diagram: class Rectangle
CS 302 Week 11 Jim Williams, PhD.
Modern Programming Tools And Techniques-I Inheritance
Interfaces.
More inheritance, Abstract Classes and Interfaces
Interface.
Introduction interface in Java is a blueprint of a class. It has static constants and abstract methods only. An interface is a way to describe what classes.
Sampath Kumar S Assistant Professor, SECE
Interfaces.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Advanced Java Programming
CSE 1030: Implementing GUI Mark Shtern.
METHOD OVERRIDING in JAVA
CSC 113: Computer programming II
class PrintOnetoTen { public static void main(String args[]) {
Chapter 14 Abstract Classes and Interfaces
Chapter 8 Class Inheritance and Interfaces
Final and Abstract Classes
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Interface

Interface In Java, an interface is a reference type, similar to a class Can contain constants and method signatures There are no method bodies Cannot be instantiated - they can only be implemented by classes or extended by other interfaces Variables and the methods declared in interfaces are public by default An interface can extend another interface A class can implement multiple interfaces www.prolearninghub.com

Interface A class that contains only abstract methods and/or named constants How Java implements multiple inheritance To be able to handle a variety of events, Java allows a class to implement more than one interface www.prolearninghub.com

Interface Why Interface? To reveal an object's programming interface (functionality of the object) without revealing its implementation To have unrelated classes Implement similar methods (behaviors) To model multiple inheritance interface Int1 { ... } interface Int2 { class Test implements Int1, Int2 { class Test1{ ... } interface Int3 { class Test extends Test1 implements Int3{ www.prolearninghub.com

Interfaces and Abstract classes can not be instantiated Example of an interface declaration: public interface Interface1 { public void set(int i); public int get(); } Interface1 i1 = new Interface1 (); Interfaces and Abstract classes can not be instantiated www.prolearninghub.com

Interface Example interface Shape { private double pi=3.14; public void getArea(int a); } class Circle implements Shape { public void getArea(int r) { double area=pi*r*r; System.out.println("Area is " + area); public class interfaceDemo { public static void main (string args[]) { Circle ci=new Circle(); c1.getArea(3); www.prolearninghub.com

Interface Example interface shape{ void area(); } }      class A6 implements shape{   public void area(){System.out.println(“This is area");}   public static void main(String args[]){   A6 obj = new A6();   Obj.area();     }   www.prolearninghub.com