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


Please Help Members By Posting Answers For Below Questions

How do I run a project in netbeans?

482


What is singleton pattern in java?

446


Does ms edge support java?

467


What's the difference between authentication and authorization? : java security

501


Write a program for the problem: the array of inetegers indicating the marks of the students is given, U have to calculate the percentile of the students aaccording to this rule: the percentile of a student is the %of no of student having marks less then him. For eg: suppose Student Marks A 12 B 60 C 80 D 71 E 30 F 45 percentile of C = 5/5 *100 = 100 (out of 5 students 5 are having marks less then him) percentile of B = 3/5*100 = 60% (out of 5, 3 have markses less then him) percentile of A = 0/5*100 = 0%.

1692






What do you mean by exception handling?

479


What are the advantages of java sockets?

661


What is jpa entitymanager?

450


Who is at risk in java? : java security

498


What are the risks in java security? : java security

465


Explain main thread under thread class execution?

483


How do I install jdk?

455


How do you count in java?

501


Can an application have multiple classes having main method?

482


What is @override annotation in java?

488