1 / 5

Static and Method Overloading

Static and Method Overloading. static. One per class, not per object static variables all instances of the class share the same static variable example: serial/VIN number for Car static methods invoked through class name, not object name cannot reference instance variables

obrienj
Télécharger la présentation

Static and Method Overloading

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Static and Method Overloading

  2. static • One per class, not per object • static variables • all instances of the class share the same static variable • example: serial/VIN number for Car • static methods • invoked through class name, not object name • cannot reference instance variables • example: Math methods, isleap, ConvertTemperature

  3. Method Overloading • Method signature – name of method and type and order of parameters • Two methods must have different signatures, but may have the same name • println(String s) • println(int i) • A class may have multiple constructors with different parameter lists

  4. Examples • Student • Constructor 1 takes first name, last name • Constructor 2 takes first name, last name, grade • StudentDB • addStudent(Student s) • addStudent(String fname, String lname)

  5. Aggregation • “Has-a” relationship • An object can have references to other objects • Example: • ContactInfo – Name, Address, Phone • Employee “has-a” ContactInfo

More Related