what are the types of constructer explain with example
Answers were Sorted based on User's Feedback
Answer / kailash
there are two types of Constructors .
1. Parameterized Constructor inwhich we give arguments .
2. Default constructor , there no argument is given .
for each class there must be a defult constructor .
Is This Answer Correct ? | 14 Yes | 2 No |
Answer / siri
there are three kinds parametrized,default and copy consturctor
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / srinu
There are Two types of constructors
1)Parameterized constructor in which give the parameter
EX:-
class A1
{
A1(int a)
{
System.out.println("HAI HOW ARE U");
}
}
public class A
{
public static void main(String k[])
{
A1 a1=new A1(5);
}
}
2)Default Constructor :- There are no argument in the
constructor is called Default Constructor
class A1
{
A1()
{
System.out.println("HAI ");
}
}
public class A
{
public static void main(String k[])
{
A1 a1=new A1();
}
}
Note: In our java class their is constructor JVM will create
one default constructor.If our class contain default
constructor or parameter constructor or both then that
time JVM will not create Default constructor
Is This Answer Correct ? | 5 Yes | 2 No |
How can I protect myself? : java security
Why is struts used in java?
What is the use of rs next () in java?
there are 67 seats in train . there are only 5 seats in a row and in last row there are only 2 seats. One person can reseve only 5 seat at a time. If person reserving seat , the care is atken that he may get all in row. if seats are not available in row then the arrangement is so that person group get nearby seats. the following class is given public class seat { char name; int seat; boolean isSeatempty } 1.Draw require class digram and object diagram. 2.Write function seatallot(int noofperson) to allocate seat with seat nuber printed for the each name.
What is lambda used for?
What is a delimiter in java?
How does java handle integer overflows and underflows?
What is messaging queue in java?
explain how java se 8 data and time api solves issues of old java date api?
I want to control database connections in my program and want that only one thread should be able to make database connection at a time. Define how can I implement this logic?
what is major difference between component and object?
How long can a lambda function run?