Searching for "Constructor"

Q:

How many constructors can a class have?

A) 1 B) 2
C) 4 D) None of the above
 
Answer & Explanation Answer: D) None of the above

Explanation:

A class can have any number of constructors. If a class have more than one constructor, we call it as the constructor is overloaded.

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Database Administration , IT Trainer

Q:

How to call a constructor in java?

Answer

Constructor chaining is the process of calling one constructor from another constructor with respect to current object.





Within same class: It can be done using this() keyword for constructors in same class


From base class: by using super() keyword to call constructor from the base class.

Report Error

View answer Workspace Report Error Discuss

Q:

Which of the following are incorrect form of StringBuffer class constructor  ?

A) StringBuffer(int size , String str) B) StringBuffer(int size)
C) StringBuffer(String str) D) StringBuffer()
 
Answer & Explanation Answer: A) StringBuffer(int size , String str)

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Database Administration , IT Trainer

Q:

A constructor estimates that 4 people can paint Mr. Karthik's house in 6 days. If he uses 5 people instead of 4, how long will they take to complete the job ?

A) 3 days B) 26/3 days
C) 13/4 days D) 24/5 days
 
Answer & Explanation Answer: D) 24/5 days

Explanation:

we know that m1 x d1 = m2 x d2
=> 4 x 6 = 5 x d
where d = no. of days taken by 5 men to paint
d = 24/5 days.

Report Error

View Answer Report Error Discuss

Filed Under: Time and Work
Exam Prep: AIEEE , Bank Exams , CAT , GATE , GRE
Job Role: Analyst , Bank Clerk , Bank PO

Q:

How are this() and super() used with constructors?

Answer

Constructors use this to refer to another constructor in the same class with a different parameter list.


Constructors use super to invoke the superclass's constructor. If a constructor uses super, it must use it in the first line; otherwise, the compiler will complain.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

How to call argument constructor?

Answer

new ClassName( arg1, arg2, .... argN);


Ex:


Class sample {


   Sample(int a) {


   System.out.println("arg con a =" +a);


   }


}


class Demo {


    Public static void main( String[] args) {


     Sample s1= new Sample(23);


     Sample s2= new Sample(45);


    }


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

What is Constructor?

Answer

Constructor is not a special method.


Constructor is block of code that is executed automatically whenever object of the class is created.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

What is Constructors and Destructors?

Answer

CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.

DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP