| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : Amit
Title :
questions and answer
Description :
Discuss these More...
|
Written By : Amit
Title :
Interview questions
Description :
Core Java Interview Questions Answer More...
|
Written By : Amit
Title :
Java Interview Questions Answer
Description :
Discuss these More...
|
Written By : Girish
Title :
ThreadPoolExecutor Example code
Description :
Explained with question answer More...
|
Written By : Sameer1
Title :
Some Questions on
Description :
Java J2EE Technology More...
|
| Tags/Keywords : interview questions Java, Java Questions Author : Amit Date (Year/Month/Date): 2009-01-27
Java Interview Questions Answer - Discuss These : | | | | |
|
Java Interview Question 1:
What is the use of final keyword in Java ?
Java Interview answer
final keyword, if used with a variable
(in its declaration), then the variable
can be initialized for once, and its
value can never be changed. All final
variables should be initialized at the
time of declaration. Values of final
variables cannot be changed.
A class, if declared as final, can not be
a super class, a method, if declared
as final, cannot be overridden.
Java Interview Question 2:
Can values of variables defined within
a final class, be changed after
instantiation? and if those variables
declared as final, then?
Java Interview answer
Yes, values of variables within final
class can be changed after instantiation,
but cannot be changed if those variables
are declared as final.
|
Java Interview Question 3:
Can Java Interface be declared final?
Justify your answer?
Java Interview Answer
No, as implementation of methods of interface is
in a different class and works in a dynamic
polymorphism paradigm and variable of type
interface will have to be initialized by a
different class, which is against the
rules of final keyword.
Java Interview Question 4:
If super class method has access modifier as
public, What are the possible access modifier
(private ,public, protected, default/no modifier)
allowed in the child class overridden method ?
Java Question Answer
Only public is allowed as access modifier in the
sub class overridden method. As there is always
a same or stronger access privilege is allowed
in method overriding.
Java Interview Question 5:
if super class method access modifier is
declared as private, then what is the access
modifier allowed in sub class overridden method?
Java Interview Answer
Method overriding is not possible in this case,
as overriding is possible only for those method
which are accessible from outside class scope,
or which are accessible from instance variable.
Java Interview Question 6:
What is the result of following code? Justify?
class A
{
int i=20;
void show()
{
System.out.println("A");
}
}
public class SubClass extends A
{
int i=30;
public void show()
{
System.out.println("B");
}
}
Client code as:
A a = new SubClass();
a.show();
System.out.println(a.i);
Result:
B - overridden method B from SubClass
20 - instance variable i from A.
As show method is overridden, then the class method (super class or sub class)
to be called is decided based on the object (new SubClass()), not on the instance
variable (A a). But in case of variable (i), as it is not overridden, then i
from A class is called.
Question 7:
What is the result of following code? Justify?
interface I
{
void show(I i);
}
class A implements I
{
int i=20;
void show(I i)
{
System.out.println("A");
}
}
public class SubClass extends A
{
int i=30;
public void show(A a)
{
System.out.println("B");
}
}
What will be the result if following code executes in the client code:
A a = new SubClass();
a.show(new A());
The result is:
A
As this show method is not overridden, due to change in the method signature.
Question 8:
While overridden method throws exception, what is the rule applicable?
Sub class method should throw an exception that is same exception as that
of the super class method throws clause or a sub class/descendent of the super
class method throws clause exception or no throws clause at all.
like,
In super class:
...
public void show() throws java.lang.Exception
{
}
....
In sub class:
...
public void show() throws java.io.IOException
{
}
....
Secondly, if super class method that is to be overridden, has no throws clause
then the overridden method in sub class should not have any throws exception,
if exists then compilation error occurs.
Question 9:
How to create user defined unchecked exception? What is the difference
between checked and unchecked exception?
User defined unchecked exception should extend java.lang.RuntimeException,
but practically there is no use of user defined exception, as unchecked
or runtime exception don't propagate to the caller through throws clause.
unchecked exception should be handled within the method body only, where
as checked exception travels through the call stack trace.
Checked exception extends java.lang.Exception , whereas unchecked exception
extends java.lang.RuntimeException.
Question 10:
Suppose try block throws an exception, catch block catches this exception
and re-throws the same exception, but finally block returns a boolean.
What could be the result/output?
finally block overwrites all the activities in try and catch block, so the output
will be the boolean returned by finally block. If finally block throws some
exception, then that will be the final exception that is propagated to the caller.
I think, purpose of the interview is to find a right candidate for
the requirement in hand, for this it is always good to have the
resume reflect only those Technologies those are well practiced
/aware of, and not just mentioned as per project/project software
used. Sometimes I have seen resumes showing Apache ANT, even if it
is used for the build purpose and used by the SCM (Software
Configuration Management) or build/release teams, and developer has
not done any contribution to it, but by mentioning it in resume,
one has to do some homework or understanding of Apache ANT, so that
he can answer at least basic questions on this.
Like some common Java Interview Questions with answer are as follows:
Java Interview Question 11.
What is basic principles of OOP?
Java Interview Answer :
Abstraction, Encapsulation, Inheritence, Polymorphism are the basic
principles of Object Oriented Programming.
Java Interview Question 12.
What is difference between abstraction and encapsulation?
Java Interview Answer :
Abstraction is looking at anything from a specific context, like
for example Televison, from viewer's context, it is just an entertainment
box, but from actor's context, it is a medium to get popular. So in this
example entertainment and popularity are two abstraction of Television.
Encapsulation is the way of providing a wrapper over the implementation.
Different colorful mobile cases are the encapsulation over mobile phone,
by this we are able to hide the internal mechanism of mobile and be able
to provide some of the switches to user to properly and easily use mobile
phone.
| |
|
| Are you interested in solving a very interesting Technology Stack while Playing this Game 
|
|
| Home >>> Interview Questions on Java >>> Java Interview Questions Answer >>> Discuss these |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
 |
Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example
code, tips, tutorials etc. Like any printed materials, content of these pages may
become out of date over a period of time. Therefore all visitor/users of this web
site are requested/advised to refer to the originating parties/sources for the
latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating
parties/sources.
By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or
downloading any materials, you agree to and are bound by the terms of use
described in this page and Usage Terms and Conditions.
If you do not agree to all of
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this
website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use
on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any
of these information, please refer original content/documentation from respective sources.
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.
|  |
|
|
|
|
|