+ 3
Constructor in java
Plz,any body give me an example of constructor programs. plz,,plz,,
6 Antworten
+ 2
you ask why is there "this." before variable name? Yeah we know that we mean "assign age argument variable to class field called age" but compiler doesn't know that, so we have to point that "this is the one field from the class" by using "this" keyword. Hence this.age = age;
+ 3
There is no such thing as "constructor program", the constructor is special method (function in class) which name has to be the same as name of class that is activated once you create instance of it eg:
class Person{
private int age;
public Person(int age)
{
this.age = age;
}
};
/////somewhere in main
Person p(20); // We've activated constructor and we passed value "20" as a parameter of "age".
Hope everything is clear, if any questions come to your mind just ask :)
+ 3
thank you but√√√
Why we use this.age or this.a,but I know that in constructor the class name is same as we use in function. I want to say that I have no basically knowledge about java programs, I am just training of java,so if you have time then,you can understand me in detail if possible hence,no any away..
+ 3
very useful topic, you may learn it properly...
very helpful to program during object creation
+ 3
Bhaijaan please visit durgasoft by ratan videos on YouTube. very great faculties there. For java Mr ratan is best.
+ 2
class example {
public int a;
public example (int a){
this. a=a;
}
}