what is constructer?what are the type of constructer with
example.
Answer Posted / prasad
A constructor is a method.it used to custom intialization
for an object.constructor name and class name is same.
consructor should not return any value not even void also.
A constructor will Executed at the time of initialization of
an object.
Different types of constructors:
--------------------------------
1)default constructor
2)parametarized constructor
Ex:
class sum{
int a,b;//instance variables
sum(int a,int b){
System.out.printl("sum of two numbers="+(a+b));
}
}
class Example{
psvm(String s[])throws Exception{
sum s=new sum(10,10);
}
}
o/p:sum of two numbers=20
/*here the constructor will be executed at the time of
creating the object*/
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Does netbeans need jdk?
What is entitymanager in jpa?
If you’re overriding the method equals() of an object, which other method you might also consider?
Write a program using call by refernce for two different classes to explain to print whether a given number is automorphic or not.
What are jdk tools?
What is @qualifier in java?
Is jdk required for netbeans?
Can we install jre without jdk?
How do I open java console?
I run a web server. Am I at risk? : java security
Can optional be null?
What is ehcache in java?
What are microservices in java?
What is an interceptor in java?
What is lambda expression in mvc?