ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
can u give one sinario when you use Abstract Class and When
you use Interface.
 Question Submitted By :: Subhranta
I also faced this Question!!     Rank Answer Posted By  
 
  Re: can u give one sinario when you use Abstract Class and When you use Interface.
Answer
# 1
when u want behavior of interface then u can implement that
inteface with any other class and after instantiate that
class u can get behavior of that interfce because by default
methods in interface are abstract,  
But in case of abstract class u can not create object of
abstract class means you can not instantiate abstact class
but after extending or by creating base class pointer ,using
dynamic method dispatch u can get behavior of abstract class
 
Is This Answer Correct ?    3 Yes 4 No
Dhawal
 
  Re: can u give one sinario when you use Abstract Class and When you use Interface.
Answer
# 2
If there are multiple objects which use common methods and 
different implementaion of methods We use Abstract class.

If multiple objects use different implementation of methods 
for every object we use interface.
 
Is This Answer Correct ?    1 Yes 1 No
Srinivasa
 
 
 
  Re: can u give one sinario when you use Abstract Class and When you use Interface.
Answer
# 3
If we have more than two classes with same method names but 
their implementation is different.we can go for interface.
Example: JDBC API Interfaces. Every data base vender 
implements these interfaces with thier implementation code.

If we want to use some common method implementaions for 
multiple classes along with their own implementation we can 
go for abstract class.

Example:Servlet API:
HttpServlet is an abstract class in which init() is 
implemented used by every servlet that extends.Every 
servlet implement their own service method.
 
Is This Answer Correct ?    2 Yes 0 No
Srinivasa
 
  Re: can u give one sinario when you use Abstract Class and When you use Interface.
Answer
# 4
Interface:
Used for mutiple inheritance.
 
Is This Answer Correct ?    0 Yes 0 No
Ajay Kumar Sharma
 
  Re: can u give one sinario when you use Abstract Class and When you use Interface.
Answer
# 5
First i will explain u abstract Class:--------------
                                                    Suppose
u open the car-show room which having all companys car and
user want to by a car, but user not sure about the company,
means user requirement is a good car. So he will come in ur
show room and ask about the every company car so how u gonna
to do this task.

So how u start.

First of all every car having some common characteristic.
That is
a)Color of car
b)Shape of car
c)gear in car
d)Type of car
e)Price of car
..........................etc.

So what we are doing is actually we are writing a abstract
class that is called Car and then we summarized the common
properties of car.

                   Why this is required because if we not
summarized the common properties of car,for every car we
have to define these common properties.Hence for that we
declare once the all common aspect of the car and the let
user choose the choice according to him.

So in abstract class we are going to define only the method
not the body and let user to allow to define his own type of
car.

abstract class Car
{
//(very important)

// we are here defining only the method not body and if any
//method end with semicolon means it is abstract method and
//if any single method in the class is abstract then class
//must be abstract. but in abstract class //we can define
the concrete method(which is not abstract) //also
public void color();  
public void price();
public void types();

Class Bmw extends car
{
//here we are define the user requirement of the car that //
is bmw and we are defining the method with body also 
public void color()
{
System.out.println("color of car is red");
}
public void price()
{
System.out.println("price of car is......");
}
}
Public Tata extends car
{
public void color()
{
System.out.println("color of car is blue");
}
public void price()
{
System.out.println("price of car is......");
}
}

I think u gain some fact about abstract class.


Interface------------------java dont have multiple
inheritance concept........so java using multiple
inheritance by INTERFACE.

Actually interface is a set of rules....it rquired when u
want to achieve multiple inheritance .
The set of rules says
1)all method are by default public staic and abstract
2)All the variables are public static and final.

So for interface u have to implements
Example

Class Anjani implements ABC(means abc is interface)

{

}

For further assistance u may call me
Anjani Kumar Jha
09623154095
CDAC,PUNE
 
Is This Answer Correct ?    1 Yes 1 No
Anjani Kumar Jha
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What is Exception handling in Java How do you handle run time errors please explain with an example TCS2
What are the limitations for static method?  2
if i have one string class then how can you achive this class functionality of this class? Fidelity3
what is the difference between HashMap And HashTable? Hexaware3
What error occurs if a try-catch-finally statement sequence does not have a catch clause?  2
what is filters and its use? Virtusa1
why there are multiple catches for a try block.don't tell me that there can be multiple exception of a code segment that's why.tell me the real fact behind this.  4
How do you set security in applets? Wipro1
Which method will get invoked first in a stand alone application?  1
they asked class A{} class B{} class c{} all the three class saved as a single file,there is no main method in the file and anothe class M.java class m { psvm(String args[]) { // here the parent class can access } } DNS1
Life Cycle of Thread IBM3
which method throws exception of type Throwable  2
In Inheritence concept, i have a static method in super class and i am inheriting that class to one sub class.in that case the static method is inherited to sub class or not???? Accenture8
Linked List reverese program Bally-Technologies1
What is synchronization? How it can be achieved?  2
By what default value is an object reference declared as an instance variable? Wipro1
In real time project which driver did u use? What is the main functionality of the Prepared Statement? Photon1
To what value is a variable of the Boolean type automatically initialized?  3
Why do we use public static with the main function in Java? Infosys7
In what type of containers, Border layout is a default layout?  3
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com