Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

"We cannot create an object of interface but we can create a
variable of it". Discuss the statement with the help of an
example.

(Plz help us to provide immediately.)

Answer Posted / prashant sharma

1.Interface myInterface{....};
2.Class myClass{......}

3.myInterface vInterace;
4.vInterface = new myClass();

In line 3 we are creating a var of type myInterface. It
holds an memory space for var type myInterface. it is just
like any other var type. Why there can't be ann object of
interface ..ans to this lies in post 1

In line 4 we create a object of class myClass. This object
returns the reference of space hold by class object on heap.
Thanks to JAVA inheritence structure, now variable
vInterface can refer to object of myClass as they are
interrelated

Interrelated in the sense taht when a class implements an
interface its object create definition of the interface in
the object on heap.

Hope it helps....

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a private method be declared as static?

965


What does localhost mean?

884


how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application

2091


What is downcasting?

1016


Why pointers are not used in java?

1044


Differentiate between a class and an object.

988


How to display arraylist values in java?

951


What are different types of inner classes ?

985


What is unsigned char?

1008


how can you catch multiple exceptions in java?

967


what is abstract class in Java?

1066


What is the requirement of thread in java?

993


Explain differences between checked and unchecked exceptions in java?

1015


Why there is no call by reference in java?

871


Define locale.

991