$public Modifier on Class Members

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

By default, all class members (variables and functions) are public. They can be accessed from outside the class definition body.

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

Examples of using $public modifier on class members:

$class circle: {

   $public pi = 3.14159;

   $public $function area(radius): {
      return ^.pi*radius**2; 
   };

   $public $function circumference(radius): {
      return ^.pi*radius*2; 
   }
}

write(circle.pi); 
write(circle.area(2.0)); 
write(circle.circumference(2.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