Basics Java
Basics Java
Ho me
Core Java Int erview Ques t ions -2 Te st
Home
Art icle s OOPS Inte rvie w Que stions Java Basic Inte rvie w Que stions
Articles Java Exc e ptions Inte rvie w Que stions Java Colle c tions Inte rvie w Que stions
T ut o rials
Java Thre ads Inte rvie w Que stions Java Ge ne ric s Inte rvie w Que stions
Spring Tutorials
Java Annotations Inte rvie w Que stions Java I/O Inte rvie w Que stions
iBat is T ut o rials
Hibernate Tutorials
Java Basic Interview Questions
Struts Tutorials
More....
31. What is Const ruct or?
Int e rvie w Q ue st io ns
A constructor is a special method whose task is to initialize the
Spring Questions object of its class.
It is special because its name is the same as t he class name.
JSF Questions
They do not have return types, not even void and therefore they
Hibe rnat e Q ue st io ns cannot return values.
Struts Questions
They cannot be inherit ed, though a derived class can call the
base class constructor.
AJAX Questions Constructor is invoked whenever an object of its associated class
JSP Questions
is created.
Servlets Questions
JDBC Questions 32. How does t he Java def ault const ruct or be provided?
Core Java Questions If a class defined by the code does not have any constructor,
XML Questions
compiler will automatically provide one no-parameter-constructor
(default-constructor) for the class in the byte code. The access
Webservices Questions modifier (public/private/etc.) of the default constructor is the same
EJB Questions as the class itself.
webMethods Questions
33. Can const ruct or be inherit ed?
Tibco Questions
No, constructor cannot be inherited, though a derived class can call the base class constructor.
BREW Questions
More....
34. What are t he dif ferences bet ween Cont ruct ors and Met hods?
Ce rt ificat io ns
Const ruct ors Met hods
Spring Ce rt ificat io n
Purpose Create an instance of a class Group Java statements
SCJP 6.0
Modifiers Cannot be abstract, final, native, static, or Can be abstract, final, native, static, or
SCJP 5.0
synchronized synchronized
SCJP 1.4
Ret urn T ype No return type, not even void void or a valid return type
SCWCD
SCBCD
Name Same name as the class (first letter is capitalized Any name except the class. Method names
by convention) -- usually a noun begin with a lowercase letter by convention --
SCEA usually the name of an action
SCMAD
this Refers to another constructor in the same class. Refers to an instance of the owning class.
SCDJWS If used, it must be the first line of the constructor Cannot be used by static methods.
J2EE super Calls the constructor of the parent class. If used, Calls an overridden method in the parent class
WebSphere must be the first line of the constructor
XML Inherit ance Constructors are not inherited Methods are inherited
PMP
UML 35. How are t his() and super() used wit h const ruct ors?
webMethods 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;
Struts
otherwise, the compiler will complain.
More....
36. What are t he dif ferences bet ween Class Met hods and Inst ance Met hods?
Class Met hods Inst ance Met hods
Instance methods on the other hand require an instance of
Class methods are methods which are declared as static.
the class to exist before they can be called, so an instance
The method can be called without creating an instance of
of a class needs to be created by using the new keyword.
the class
Instance methods operate on specific instances of classes.
Class methods can only operate on class members and not Instance methods of the class can also not be called from
on instance members as class methods are unaware of within a class method unless they are being called on an
instance members. instance of that class.
Class methods are methods which are declared as static.
The method can be called without creating an instance of Instance methods are not declared as static.
the class.
37. How are t his() and super() used wit h const ruct ors?
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.
38. What are Access Specifiers?
One of the techniques in object-oriented programming is encapsulation. It concerns the hiding of data in a class and making this
class available only through methods. Java allows you to control access to classes, methods, and fields via so-called access
specifiers..
Accessible to class
yes yes yes no
from same package?
Accessible to class
yes no, unless it is a subclass no no
from different package?
where, the name of the variable is varIdentifier and its data type is specified by type.
Not e: Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default
value depends on the data type of the variables.
� Pre vious | 1 2 3 4 5 | Ne xt �
ALSO SEE :
About Us | O ur Mission | Terms of use | Author Terms | Se arch | Contact Us | Advertise With Us | Link to Us | Sitemap