4D Blog

Home Product Object-oriented programming in 4D: Manage class inheritance

Object-oriented programming in 4D: Manage class inheritance

May 6, 2020

Product

In a previous blog post, we introduced a very important concept in object-oriented programming: Classes. Now we’ll go through another core concept: Inheritance, the mechanism that allows a class to acquire the behavior of another class.

Example database

Remember the example in the previous blog post with the “Person” class ? Let’s imagine a school and we want to manage students and teachers. Both are persons, but with different characteristics. So we create a “Teacher” class and a “Student” class, and both classes inherit characteristics from the “Person” class.

 

How do you inherit A class from another?

A new Class extends keyword is now available to facilitate inheritance. Using our school example, we create a “Student” class that inherits the “Person” class.

Class Extends Person

And the constructor?

Then for the constructor (if you haven’t defined a specific constructor for the “Student” class), the constructor of the “Person” class is automatically called.

You can also override a constructor. For example in the case of “Student”: a student has a name, surname, and date of birth as a person, but a student also has a grade and a school. In this case, you can use the new Super command which allows you to call the constructor of the parent class. Then in the “Student” constructor, you can add the specific code for grade and school.

Class constructor
 C_TEXT($1) // FirstName
 C_TEXT($2) // LastName
 C_DATE($3) // Birthdate
 C_TEXT($4) // SchoolName
 C_TEXT($5) // Grade
 Super($1;$2;$3) // Call the "Person" constructor
 This.SchoolName:=$4
 This.Grade:=$5

And the functions?

You can add functions specific to the “Student” class from which you can call a function of the parent class (“Person”).

In the following example, we have a function that returns a string containing the student’s name, grade, and school. In the class “Person”, we already have a function that returns the full name of a person. So we call this function, getFullName, and add the information specific to a student.

Function getIdentity
 C_TEXT($0)
 $0:=Super.getFullName()+", "+This.Grade+" grade in "+This.SchoolName

In a method, we instantiate an instance of the “Student” class. We call the getFullName function from the parent class, “Person”. Then, we call the getIdentity function from the “Student” class. As you can see, there are no differences between the getFullName and getIdentity functions.

C_OBJECT($s)
$s:=cs.Student.new("Joe";"Doe";!2002-02-20!;"Waco High School";"10th")

$name:=$s.getFullName() //return John Doe
$identity:=$s.getIdentity() //return Joe DOE, 10th grade in Waco High School

A live demonstration to summarize

Discuss

Tags Class, Programming, Project, Project database, v18 R3, v19

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • Release infos
  • 4D View Pro
  • 4D Write Pro
  • Email, Microsoft 365, Gmail
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • 4D Qodly Pro
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy