Sunday, 8 April 2012


class A implements XYZ{
public void test(){}
}
-Since and interface is an abstract entity, it cannot be instantiated i.e. an object cannot be created just like an abstract class.
===
implement Vs. override
-implement means to provide a method body
-override means to replace the existing body with a newer one
-an implementer class MUST implement all methods of an interface otherwise it will become abstract
---
-An interface reference can be created to hold objects of implementor classes
Why:
Super class reference variable can be used to hold a child class object reference
e.g.
interface X{
public void t()
}
class A implements X{
public void t{}
}
int main(){
X refX = new A();
}
---

-an interface can inherit from other interfaces
Why:
an interface contains only method declarations and more method declarations can add to this list of declarations
e.g.
interface X{
public void a();
}
interface Y extends X{
public void b();
}
//the following class must provide implementation for both a() and b()
class ABC implements Y{
public void a(){}
public void b(){}
}
---


Abstract Class : Contain Abstract and Concrete Methods
Interface : Can extends Interface, Abstract Methods and Concrete class.

e.g

interface xyz
{
1 Method declare
2 Method declare
}
Class A implements xyz
{
1....(){}
2....(){}
}
If all the methods of interface class are not defined in the implement class, then it is called abstract class.

E.g:

interface xyz
{
1 Method declare
2 Method declare
}
Class A implements xyz
{
2....(){}
}

Question


Which statements about interfaces are true?

Select the two correct answers.

(a) Interfaces allow multiple implementation inheritance.

(b) Interfaces can be extended by any number of interfaces.

(c) Interfaces can extend any number of interfaces.

(d) Members of an interface are never static.

(e) Members of an interface can always be declared
static.

No comments:

Post a Comment