Classes (programming)

A class (in programming) is a grouping of data (variables or fields) and of functions (methods) that operate on that data. These data and functions belonging to a class are called variables and methods or member functions. The OOP is based on class scheduling.

Summary

[ hide ]

  • 1 Introduction
  • 2 Variables
  • 3 Builders
  • 4 Classes and Abstract Methods
  • 5 Sources

Introduction

A program is built from a set of classes. Once a class is defined and implemented, it is possible to declare elements of this class in a similar way to how the variables of the language are declared (of the primitive types int, double, String, …). The declared elements of a class are called objects of the class. Numerous objects can be declared or created from a single class. Class is generic: it is the pattern or model for creating objects. Each object has its own copies of the member variables, with their own values, generally different from the other objects in the class. Classes can have static variables, which are specific to the class and not to each object.

Variables

A variable is a name that contains a value that can change throughout the program. According to the type of information they contain, these are classified into 2 or more types depending on the programming language used, in general there are 2 types of classifications: 1 – Variables of primitive types. They are defined by a unique value that can be integer, floating point, character or boolean. Every programming language like Javafor example, they allow different precisions and value ranges for each type of variable (char, byte, short, int, long, float, double, boolean). Examples of primitive type variables could be: 123, 3456754, 3.1415, 12e-09, ‘A’, True, etc. 2. Reference variables. Reference variables are references or names of more complex information: arrays or objects of a certain class.

 

Builders

A key point of Object Oriented Programming is to avoid incorrect information because the variables have not been correctly initialized. The second step in correct initialization of objects is the use of constructors. A constructors is a method that is automatically called every time an object of a class is created. The main mission of the constructors is to reserve memory and initialize the member variables of the class. Constructors have no return value (not even void) and their name is the same as the class. Its implicit argument is the object being created.

Abstract Classes and Methods

An abstract class (abstract) is a class from which objects cannot be created. Its usefulness is to allow other classes to derive from it, providing them with a framework or model to follow and some methods of general utility. Abstract classes are declared by prefixing the word abstract (In some programming languages), such as public abstract class Geometry {…} An abstract class can have methods declared as abstract, in which case no method definition is given. If a class has an abstract method, the class must be abstract. In any sub-class this method must either be redefined, or re-declared as abstract (the method and the sub-class). An abstract class can have methods that are not abstract. Although objects of this class cannot be created, its subclasses will inherit the method completely ready to be used. Since static methods cannot be redefined, an abstract method cannot be static.

 

 

Leave a Comment

Scroll to Top