"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

What is the use of callablestatement?

567


Can we override constructor in java?

567


What are the different types of methodologies?

522


What do you mean by chromounits in java8?

521


What are the advantages of unicode?

539






How do you sort arrays in java?

517


what is the difference between Object Based Language and Object Oriented Language?

591


What is the use of runnable interface?

599


What is size () in java?

536


What is use of map in java?

503


What is immutable data?

573


What is java lang string?

540


What is http client in java?

513


What is super?

576


What is a instance variable in java?

541