$public Modifier on Instance Members

This section describes the $public modifier on Instance members (variables and functions).

By default, all instance members (properties and methods) are public. They can be accessed from outside the instance definition body.

But if you want to make the code more readable, you use the $public modifier to declare instance members to be publicly accessible.

Examples of using $public modifier on instance members:

$class account: {
   $insance x: {
      $public x.balance = 0.0;
	  $public $method x.deposit(amount): {
         x.balance = x.balance + amount; 
      };
	  $public $method x.withdraw(amount): {
         x.balance = x.balance - amount; 
      };
	  $public $method x.printBalance(): {
         write(x.balance); 
      };
   }
}

checking = account();
checking.deposit(100.0);
checking.deposit(80.0);

checking.printBalance(); # prints 20.0

Last update: 2017.

Table of Contents

 About This Book

 Introduction of H Language

 Syntax

 Data Types

 Variables

 Expressions

 Statements

 "boolean" Data Type

 "integer" Data Type

 "string" Data Type

 "real" Data Type

 "array" Data Type

 Source Code Packages

 Classes and Objects

 Object Oriented Programming

 Inheritance - Object Attachments

Encapsulation - Private Members

 $public Modifier on Class Members

 $private Modifier on Class Members

$public Modifier on Instance Members

 $private Modifier on Instance Members

 "protected" Modifier Not Supported

 References

 PDF Printing Version