Professional Documents
Culture Documents
void readNiceQuotes();
4.
int loveTaraMore();
5.
6. }
7.
8. class HappyAnnessha implements Annesha{
9.
10.
11.
12.
13.
14.
return infnity;
15.
16.
17.
18.
19.
20.
21.
22.
System.out.println("Jao.");
23.
24.
25.
26.
27.
return (infinity-1);
28.
When a class implements an interface, you can think of the class as signing
a contract, agreeing to perform the specific behaviors of the interface. If a
class does not perform all the behaviors of the interface, the class must
declare itself as abstract.
A class uses the implements keyword to implement an interface. The
implements keyword appears in the class declaration following the extends
portion of the declaration.
Interface
Interface
Interface
Interface
Interface
First one uses the classes and the second one uses Interfaces
/***********************Using Classes*************/
class A
{
public void methodAClassA()
{
System.out.println("In ClassA MethodA");
}
}
class B extends A{
public void methodAClassA(){
System.out.print("in Class B Method ClassA");
}
}
class C extends A,B {
/*
* Which is not possible becuase
* if u use the above code the compiler does not
* know which instace method could be used in the class C
* So they made it as error it will show the compilation error
*
*/
}
/******************Using Interfaces*******************/
interface A
{
public void methodAClassA();
}
interface B extends A{
public void methodAClassA();
}
class C implements A,B {
/*
* Which is possible becasue
* if we use the above code there is no need of the
* knowing which method instace could be used
*/
}