Cards (6)

  • What is a Method
    • Methods are fundamental in object-oriented programming (OOP) and are functions associated with objects or classes that define the behaviour and actions that objects can perform 
    • There are two main types of methods
    • A function 
    • A function performs a task and returns a value 
    • A procedure 
    • A procedure performs a task buts does nor return a value 
    • For example, there are many different types of aircraft which all differ in design, but all require a ‘take off’ and ‘landing’ method 
  • Methods image
  • Methods #2
    • Each object that is created from the aircraft class will have: 
    • A manufacturer value to determine the company that created the aircraft 
    • A model name for the type of aircraft 
    • A value for passenger capacity to determine how many people it can carry 
    • A speed value to determine its maximum speed
  • Methods #3
    • Any objects that are created for the aircraft class also have access to the following Methods: 
    • A take off method to get the plane airborne 
    • A land method to land the plane safely 
    • A bank left method to allow the plane to turn to the left 
    • A bank right method to allow the plane to tur to the right 
  • Methods #4
    • As you can imagine, for an aircraft there would be many more methods that could be implemented such emergency landing and altitude cruising actions 
    • Once objects have been created, they can use the methods from within their class by using the dot (.) notation 
    • As these methods are associated with objects, they are called instance methods 
    • For example if an object has been created as below: 
    • jumboJet = new aircraft (“Boeing”, ”747”, 416, 547) 
    • It can use methods by doing the following: 
    • Objectname.Methodname: 
    • For example:    jumboJet.Takeoff() 
  • Public vs Private Methods