Interview Questions on Constructor in Java for Freshers

Why use constructor ?

The main purpose of create a constructor is, for placing user defined values in place of default values.


Why constructor not return any value ?

Constructor will never return any value even void, because the basic aim constructor is to place value in the object


Why constructor definition should not be static ?

Constructor definition should not be static because constructor will be called each and every time when object is created. If you made constructor is static then the constructor before object creation same like main method.


Why constructor is not inherited ?

Constructor will not be inherited from one class to another class because every class constructor is created for initialize its own data members.


What is purpose of default constructor ?

The purpose of default constructor is to create multiple object with respect to same class for placing same value.


What is purpose of parameterized constructor ?

The purpose of parametrized constructor is to create multiple object with respect to same class for placing different value of same type or different type or both.


Is constructor inherited?

No, constructor is not inherited.


Can you make a constructor final?

No, constructor can't be final.


What is the purpose of default constructor?

The default constructor provides the default values to the objects. The java compiler creates a default constructor only if there is no constructor in the class.


Can we use both "this" and "super" in a constructor ?

No, because both this and super should be the first statement.


Does constructor return any value?

yes, that is current instance (You cannot use return type yet it returns a value).


What is flow of constructor in Java ?

Constructor are calling from bottom to top and executing from top to bottom.


Why overriding is not possible at constructor level. ?

The scope of constructor is within the class so that it is not possible to achieved overriding at constructor level.


Difference between Method and Constructor


MethodConstructor
1Method can be any user defined nameConstructor must be class name
2Method should have return typeIt should not have any return type (even void)
3Method should be called explicitly either with object reference or class referenceIt will be called automatically whenever object is created
1Method is not provided by compiler in any case.The java compiler provides a default constructor if we do not have any constructor.

Related

TCS Technical & HR Interview Question and Answers for Freshers

Before the Interview: 1. Visit the company’s website ·         Be able to articulate what you learned including you...

Latest CSS Interview Question for Freshers

What is css Cascading Style Sheets (CSS) is a rule based language that applies styling to HTML elements. Why use CSS We write CSS rules in html elements (, ), and modify properties of those ele...

Latest Servlet Interview Question for Freshers

Why a Servlet class should be a public ? A web container internally calls newInstance() method for creating an object of a Servlet class newInstance() method first checks whethe...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item