Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)

Slides:



Advertisements
Similar presentations
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Advertisements

Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
CS110 Programming Language I
Procedural programming in Java
PAC Introduction to Methods Professor: Evan Korth New York University.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Chapter 5 Functions.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 5 Function Basics.
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Introduction to Computers and Programming Introduction to Methods in Java.
Introduction to Computers and Programming Lecture 12: Math.random() Professor: Evan Korth New York University.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Math class methods & User defined methods Math class methods Math.sqrt(4.0) Math.random() java.lang is the library/package that provides Math class methods.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Introduction to Java Programming, 4E Y. Daniel Liang.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
Review for Midterm 2 Nested loops & Math class methods & User defined methods.
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
 2006 Pearson Education, Inc. All rights reserved. Templates (again)CS-2303, C-Term Templates (again) CS-2303 System Programming Concepts (Slides.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
1 Topic 04 Methods Programming II/A CMC2522 / CIM2561 Bavy Li.
 2003 Prentice Hall, Inc. All rights reserved Introduction Modules –Small pieces of a problem e.g., divide and conquer –Facilitate design, implementation,
Lecture From Chapter 6 & /8/10 1 Method of Classes.
Introduction to Computers and Programming Lecture 14: User defined methods (cont) Professor: Evan Korth New York University.
ECE122 Feb. 22, Any question on Vehicle sample code?
Procedural programming in Java Methods, parameters and return values.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 6.
1 Chapter 6 Methods. 2 Motivation Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.
Lecture 5 functions 1 © by Pearson Education, Inc. All Rights Reserved.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
Chapter 5 Methods 1. Motivations Method : groups statements that perform a function.  Level of abstraction (black box)  Code Reuse – no need to reinvent.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Classes - Intermediate
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Methods.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
 2006 Pearson Education, Inc. All rights reserved Templates.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 6 Methods.
INF120 Basics in JAVA Programming AUBG, COS dept Lecture 07 Title: Methods, part 1 Reference: MalikFarrell, chap 1, Liang Ch 5.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 6.
Operator Overloading; Class string
Chapter 5 Functions DDC 2133 Programming II.
Introduction to Methods
Data Types.
Methods Additional Topics
2011/11/10: Lecture 21 CMSC 104, Section 4 Richard Chang
Chapter 5 Function Basics
Group Status Project Status.
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Java Lesson 36 Mr. Kalmes.
Copyright © 2008 Pearson Prentice Hall Inc.
Method Overloading in JAVA
CS2011 Introduction to Programming I Methods (II)
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Copyright © 2008 Pearson Prentice Hall Inc.
Chapter 6 Methods.
Chapter 5 Methods.
BBIT 212/ CISY 111 Object Oriented Programming (OOP)
Unit-1 Introduction to Java
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Corresponds with Chapter 5
Chapter 6: Methods CS1: Java Programming Colorado State University
Presentation transcript:

Overloading methods

review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b) public static void nPrintln (String s, int n) public static int max (int a, n) public static String pickLine ()

 2000 Prentice Hall, Inc. All rights reserved Method Overloading Method overloading –Several methods of the same name –Different parameter set for each method Number of parameters Parameter types –The Java compiler determines which method to use based on the parameters. –Can also be used in conjunction with argument coercion. The combination can lead to ambiguous invocation which is an error

Understanding Scope