0

Can you please explain easily about private public in class and also about constructors in classes with examples ?

23rd Jul 2020, 9:36 AM
Pulasani Aswini
Pulasani Aswini - avatar
8 Respuestas
+ 1
If java,then public ,private and protected are access modifiers.If the method or variable is made public then it can be used anywhere. If private,then it can be accessed by only that class.If protected ,then it can be used by the inherited class only. Constructed are used as method to initialize the variable on being run .
23rd Jul 2020, 12:48 PM
shubham kumar
shubham kumar - avatar
0
A public variable/function can be accessed in other classes while a private one is only accessible in the class it was defined. A constructor is a fuction inside of a class that will be executed when an instance of a class is created. If you want examples you have to put the programing language in the tags so i know in which languge to write the examples
23rd Jul 2020, 9:47 AM
Andrei I
Andrei I - avatar
0
C++
23rd Jul 2020, 10:00 AM
Pulasani Aswini
Pulasani Aswini - avatar
0
I will send you a commented code wait a bit
23rd Jul 2020, 10:02 AM
Andrei I
Andrei I - avatar
0
Ok
23rd Jul 2020, 10:02 AM
Pulasani Aswini
Pulasani Aswini - avatar
23rd Jul 2020, 10:24 AM
Andrei I
Andrei I - avatar
0
The output will be text1text2 if you uncomment the line instance.Private() it will give an error
23rd Jul 2020, 10:26 AM
Andrei I
Andrei I - avatar
0
Mention related to which programming language.
23rd Jul 2020, 12:44 PM
shubham kumar
shubham kumar - avatar