+ 2
Can we pass argument to constructors in java ??
How to pass arguments to constructor in java ??
4 ответов
+ 10
ConstructorName (int arg){
doSomething ();
}
___________
ConstructorName foo = new ConstruktorName (25);
+ 8
It is simmilar to other methods. For example assume you have a class named Student which has a member variable age. Define a constructor as follows:
public Student(int age){this.age=age;}
Now defining an object of this class you can set its age:
Student st= new Student(20);
Then st.age equals 20.
+ 5
you should define it in its class.
+ 2
OK THANKS I WILL TRY TO DO THIS !! WAIT !