Week 4 Recap - PowerPoint PPT Presentation

About This Presentation
Title:

Week 4 Recap

Description:

interface: keyword indicating the start of an interface ... public: keyword as before ... If no information comes back return type is void (another keyword) ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 13
Provided by: cseBu
Learn more at: https://cse.buffalo.edu
Category:

less

Transcript and Presenter's Notes

Title: Week 4 Recap


1
Week 4 Recap
  • CSE 115 Fall 2006
  • Section C

2
Decoupling
  • Separation of concerns
  • Defining what an object can do, not how it does it

3
Interfaces
  • One way to achieve decoupling in Java is through
    interfaces.
  • An interface definition consists of an interface
    header and an interface body.

4
Interface Header
  • public interface Name
  • public keyword meaning the same as before
  • interface keyword indicating the start of an
    interface definition
  • Name identifier name of interface. Interface
    names by convention start off with a capital I,
    but then use same conventions as class names

5
Interface Body
  • Enclosed in
  • Contains what capabilities elements should have
    if they implement the interface.

6
Methods
  • Formal specifications of capabilities inside our
    classes
  • Method definitions consist of a method header and
    a method body

7
Method Definition (Method Header Part 1)
  • public type name()
  • public keyword as before
  • type indication of the return type of the method
    what information comes back from a method call?
    If no information comes back return type is void
    (another keyword)

8
Method Definition (Method Header Part 2)
  • public type name()
  • name identifier for method method names follow
    conventions of class names, except the names
    begin with a lower case letter.
  • () called a formal parameter list gives us a
    list of information that the method needs to
    finish its task.

9
Formal Parameter Lists
  • Comma-separated list of formal parameters
  • Formal parameters are listed giving the type of
    the parameter followed by a name
  • (type1 name1, type2 name2, type3 name3)

10
Calling methods
  • To get the actions of a method to be performed,
    we need to call (or invoke) the methods
  • Methods are called on objects
  • How do we get an object?

11
Method calls
  • object.methodToBeCalled()
  • Recall the dot (.) operator or member access
    operator
  • Notice the () here this is an actual parameter
    list. If the method needs a parameter, we need
    to give an actual value to the method when we
    call it.

12
Important Note
  • Two methods in Java can not have the exact same
    method header.
Write a Comment
User Comments (0)
About PowerShow.com