0
Give real example of constructor ....
its use , the way it's being used
2 ответов
+ 2
class Example {
private int a= 1;
public void doStuff()
{a+=1;}
}
public class MyApp {
public static void main (string[] args){
Example ex = new Example();//here are the only way constructor should be used
ex.doStuff();}}
new keyword create object constructor call Example() ; initialize it thats it.
If you trying to do something in constructor apart from it, you are doing it wrong. Each method should do only on thing, constructor should "construct" object.
0
thanks for ur reply , now my question is what's the differences between method & contractor??? still stuck why it is used😢