Showing posts with label learn java at Bopal-ahmeabad. Show all posts
Showing posts with label learn java at Bopal-ahmeabad. Show all posts

Wednesday, August 31, 2022

What is the Difference between function overloading and function overriding?

 

Function Overloading

 

It is a technique in object-oriented programming when two or more functions have the same name, but different parameters.

 

When a function name is overloaded with multiple assignments, then it is said to be function overloading.

 



 

Example:-

#include <iostream>

using namespace std;

void sum(int x, int y)

{

                cout << "Addition is…" << (x + y);

}

 

void sum(double x, double y)

{

                cout << endl << " Addition is… " << (x + y);

}

 

int main()

{

                sum(10, 20);

                sum(10.25, 20.35);

 

                return 0;

}

 

Output:-

Addition is = 30

Addition is = 30.6

 

Function Overriding

It is a technique when the base class and derived class have same member functions with same return-type, and same arguments list, then it is said to be function overriding.

 

#include <iostream>

using namespace std;

 

class BaseClass

{

public : void show()

{

              cout << "Base Function called" << endl;

}

};

 

class DerivedClass : public BaseClass

{

public : void show()

{

              cout << "Derived Function called" << endl;

}

};

 

int main()

{

              DerivedClass dc;

              dc.show();

              return 0;

}

 

Output:-

Derived Function called

 

Difference between function overloading and function overriding

 

Function Overloading

Function Overriding

Function Overloading is  a compile-time polymorphism.

Function overriding is a run-time polymorphism.

It helps to increase the readability of the program.

It is generally used to grant the specific implementation of the method which is already provided by its parent class or superclass.

It occurs generally within the class.

It is performed in two classes with inheritance relationships.

Function overloading may or may not require inheritance.

Function overriding always needs inheritance.

In function overloading, function must have the same name and different signatures.

In function overriding, function must have the same name and same signature.

In function overloading, the return type can or cannot be the same, but we just have to change the parameter.

In function overriding, the return type must be the same or co-variant.

The function must have different number of parameters. If both the function have the same number of parameters, then their type must be different.

Both the function must have the same number of parameters with the same type.

 

TCCI provides best teaching in various programming courses through different learning method/media as per students convince.

 

For More Information:                                          

Call us @ 9825618292

Visit us @ http://tccicomputercoaching.com  

 

Is C a Procedure Oriented Programming Language?

 

C is a programming language which developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by Dennis Ritchie in the late seventies. C is also one of the oldest and finest programming languages.

 


 

Syntax:-

 

#include<stdio.h>

 

int main() {

 

printf(“Hello I am learning C Program”);

 

return 0;

 

}

 

Syntax:-

 

Hello I am learning C Program

 

A procedural-oriented programming language which contains a small bunch of code blocks called procedures to solve any complex problem. These programming languages help debugging because we can easily isolate the error-containing procedure.

 

Procedural programming language is based on the concept of the Procedure call which is a programming paradigm that makes use of procedures as per program execution (also called routines, subroutines, functions etc.).

 

Most of the programming languages in the early days were used the concept of Procedural based programming.

 

It is also known as Imperative Programming because of well-structured computational phases which make use of features like modularity and scoping to increase its readability and decrease its complexity.

 

Modularity refers to the regular division of a complex code into small pieces. It will reduces the complexity of a program and makes easier to find and edit any part of the code as and when required.

 

Scoping refers to enclosing the variables, constants, and other statements and functions in a programing module.

 

Scoping and modularity are closely related with each other as scoping are used to implement modularity.

 

A program gets divided into small stages for which the variables have a scope and cannot/can be accessed by other functions according to the programmer’s optimal.

 

Why ‘C’ is a Procedural Oriented Programming

 

Ø  C languages mostly uses the set of instruction to inform computer what to do step by step.

Ø  Its generally depend in the procedures, more specifically routines or sub routines.

Ø  C language follows the procedures hence it adopt top-to-down approach.

Ø  C languages is very much focused on procedure that relates with the data.

Ø  C languages is much focused on the data hence on functions.

Ø  It is also well known as structured programming language.

 

TCCI provides best teaching in various programming courses through different learning method/media as per students convince.

 

For More Information:                                          

Call us @ 9825618292

Visit us @ http://tccicomputercoaching.com