Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.

Slides:



Advertisements
Similar presentations
Phil Campbell London South Bank University Java 1 First Steps.
Advertisements

Old MacDonald had a farm
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
CSCI 160 Midterm Review Rasanjalee DM.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
Unit 211 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 10: 1 TEST!!
Unit 201 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Old MacDonald.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
Programming Progamz pls. Importance VERY IMPORTANT.
Sun Certified Java Programmer, ©2004 Gary Lance, Chapter 8, page 1 Sun Certified Java 1.4 Programmer Chapter 8 Notes Gary Lance
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Introduction to Java Classes and Objects. What is a class A class is description of a structure that contains both data and methods – Describes a set.
BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS. 22 OBJECTIVES Recognize different errors that Java uses and how to fix them.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
Object-Oriented Programming Simple Stack Implementation.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
CSI 3125, Preliminaries, page 1 Compiling the Program.
Java Basic Syntax. Object - Objects have states and behaviors. –Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating.
Singleton Pattern Presented By:- Navaneet Kumar ise
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
ENGINEERING PRINCIPLES Computer Science: Functions.
Staples are our staple Building upon our solution.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Java Memory Management
Lecture 12 Inheritance.
Java Memory Management
Arrays 3/4 By Pius Nyaanga.
Exercise Java programming
Maha AlSaif Maryam AlQattan
Week 8 Lecture -3 Inheritance and Polymorphism
Old MacDonald Had a Farm
Writing Methods.
Interface.
CMSC 202 Interfaces.
Interfaces and Constructors
The this Reference The this reference allows an object to refer to itself That is, the this reference, used inside a method, refers to the object through.
Assignment 7 User Defined Classes Part 2
مظفر بگ محمدی دانشگاه ایلام
class PrintOnetoTen { public static void main(String args[]) {
CMSC 202 Interfaces.
Constructors, GUI’s(Using Swing) and ActionListner
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Chapter 14 Abstract Classes and Interfaces
Lecture 11 Parameters CSE /26/2018.
Chapter 11 Inheritance and Polymorphism Part 1
slides created by Ethan Apter
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
CMSC 202 Interfaces.
CSG2H3 Object Oriented Programming
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Interfaces

–An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java classes implement one or more interfaces –Let's begin with a simple interface.

Old MacDonald had a farm –Interfaces have public method headings followed by semicolons. no { } –No methods are implemented: Some other will do it public interface BarnyardAnimal { public String sound( ); }

One or classes will implement an interface –To implement an interface, you must have all method specified exactly as written in the interface. public class Cow implements BarnyardAnimal { public String sound( ) { return "moo"; } public class Chicken implements BarnyardAnimal { public String sound( ) { return "cluck"; }

What is the output? public class OldMacDonald { public static void main(String[] args) { BarnyardAnimal animalOne = new Cow( ); BarnyardAnimal animalTwo = new Chicken( ); System.out.println( "With a " + animalOne.sound() + " " + animalOne.sound() + " here," ); System.out.println( "and a " + animalTwo.sound() + " " + animalTwo.sound() + " there." ); System.out.println( "Here a " + animalOne.sound()); System.out.println( "there a " + animalTwo.sound()); System.out.println( "everywhere a " + animalTwo.sound() + " " + animalTwo.sound() + "." ); }

Interfaces –Interfaces are used by Java in several ways. event-driven programs –They can also be used to specify class design. They list all the methods that you must implement You add instance variables and constructors