Methods: Objects as Parameters and Return Values - ISC Class 12 Computer Science Notes, Diagrams and Solved Questions

Methods as operations on objects: formal and actual arguments, why primitive and object arguments behave differently, the this reference, static variables and methods, methods that combine two objects, and passing and returning objects and arrays.

In this chapter

  • Recap of classes, objects, constructors and method headers
  • Formal and actual arguments, and why a primitive argument cannot be changed by a method
  • Object arguments: a copied reference lets a method change fields but not reassign the caller's variable
  • The this reference for fields, comparisons and method chaining
  • Static variables and static methods, and why they have no this
  • ISC-style methods that work on two objects, such as addTime(Time t1, Time t2)
  • Returning a new object, as in Fraction add(Fraction f)
  • Passing arrays to methods and returning arrays