Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Software Engineering Tutorial
  • Software Development Life Cycle
  • Waterfall Model
  • Software Requirements
  • Software Measurement and Metrics
  • Software Design Process
  • System configuration management
  • Software Maintenance
  • Software Development Tutorial
  • Software Testing Tutorial
  • Product Management Tutorial
  • Project Management Tutorial
  • Agile Methodology
  • Selenium Basics
Open In App
Next Article:
Creating Function in Files in MATLAB
Next article icon

Overloading Functions in Class Definitions in MATLAB

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The overloading Function is like in all other programming languages the definition of Overloading functions. It is basically defined as more than one function with the same name but different parameters and data types. In other words, function overloading is the feature of Object Oriented Programming where two or more functions can have the same name but different parameters. When a function name is overloaded with different jobs it is called Function Overloading. It can be considered an example of Polymorphism in MATLAB.

It is the concept of using more than one function with the same name to perform different tasks in the same program suppose for example if we have to calculate the sum of two numbers. Now the case is that one time we have to add integer values and in another case, we have to add floating values So to encounter this problem we can use the Overloading function with the same name but different parameters.

  1. sum_of_numbers(int x, int y) for the sum of integer values.
  2. sum_of_numbers(float a , float b , float c) for the sum of decimal values. 

We can easily understand it with the help of the Example :

Example 1: 

Matlab
% Code for polymorphism in MATLAB classdef Vehicle                      methods                      function testing(self)                 disp('This is a car ');                                  function testing(self)                 disp('This is a Motorcycle');         end     end end 

So here in this program we first create a class name Vehicle then we define two functions with the same name but different functions. Now in output, we will see the working of both functions.

Output :

 

Explanation:

So Here in this program, there are two functions with the same name In the output we first call the first function after calling the first function we get the statements of the first function like as :

xyz = Vehicle;

testing(xyz);

--) This is a car 

  Now we call the function again with the same process then we get the result of the second function the statement of the second function will be displayed on the output shell.

xyz = Vehicle;

testing(xyz);

--) This is a Motorcycle 

So the conclusion is that it works similarly like to it works in other programming languages.

There are some points or a few steps keep in mind while writing an Overloaded MATLAB program these points are as follows:

  1. First of all, we have to define a method that has the same name as the function in the MATLAB program.
  2. Now we have to check or verify that the method we have declared has accepted the object of the class.
  3. Now we have to check that the method which contains the object of the class uses the same version of MATLAB.
  4. Now we have to complete all the other required steps to generate the output of the program or code. 

So it works similarly to all other programming languages there is no specification to write an overloaded program it is just simple and basic in all other programming languages same is in MATLAB. Because it is also a High-level programming language.


Next Article
Creating Function in Files in MATLAB
author
aakashattri111
Improve
Article Tags :
  • Software Engineering
  • MATLAB-OOPs

Similar Reads

  • Plot Expression or Function in MATLAB
    In this article, we will discuss how to plot expressions or functions in MATLAB. We can make use fplot() function in MATLAB to generate the plot corresponding to an expression or function. There are different variants of fplot() function fplot(f)fplot(f,xinterval)fplot(___,LineSpec)fplot(___,Name,Va
    3 min read
  • Defining Function Handles in MATLAB
    A MATLAB data type that represents a function is called a function handle, in other words, we say that The function handle is a typical data type in MATLAB. Function handles can therefore be modified and used in the same way as other MATLAB data types. Using function handles in arrays, structures, a
    3 min read
  • Creating Function in Files in MATLAB
    MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory.  Functions:The function is a set of statements or commands, which take input/s as parameters and return output. We write functions to
    2 min read
  • Function Argument Validation in MATLAB
    The basics of Function Argument is, " The functions receive certain inputs from the calling command which applies in function syntax and processes it. sometimes It may or may not produce output argument it dependence completely on the functions efficiency or the accuracy of your code." Function Argu
    5 min read
  • Inline and Anonymous Functions in MATLAB
    Methods are also popularly known as functions. The main aim of the methods is to reuse the code. A method is a block of code that is invoked and executed when it is called by the user.  Inline FunctionInline functions are the kind of functions which is defined in one line. that's why this type of fu
    4 min read
  • Class Constructor Methods in MATLAB
    Class constructors are special methods in MATLAB that are used to create an instance of a class. In other words, they are used to initialize the properties of an object when it is created. Class constructors typically have the same name as the class itself, and they are defined as methods within the
    4 min read
  • Anonymous Functions in MATLAB
    A block of code that is organized in such a way that is reusable for the entire program. Functions are used for reducing efforts made by writing code and making the program short, and easily understandable.  There are different syntaxes for declaring a function in different programming languages. In
    5 min read
  • Clean Up When Functions Complete in MATLAB
    While working in MATLAB, handling the workspaces is crucial for the proper working of multiple scripts and functions. That is why it is a healthy habit to clean up the MATLAB workspace once a function execution is completed. Some of the requirements for performing a cleanup routine, cleaning up all
    4 min read
  • Function Declaration vs. Function Definition
    Function Declaration introduces the name, return type, and parameters of a function to the compiler, while Function Definition provides the actual implementation or body of the function. Declarations enable calling the function elsewhere in the code, while definitions provide the code to be executed
    2 min read
  • Fruitful Functions and Void Functions in Julia
    Functions are one of the most useful tools when writing a program. Every programming language including Julia uses functions, it can be for keeping the code simple and readable or to keep the program secure from outside interference. In almost every programming language there are two types of functi
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences