1

I am beginner in Java. I know the concept of Interface. Interface is mainly used to achieve full abstraction and to support the functionalities of Multiple Inheritance and then loose coupling.

There can be abstract methods and static constants. It cannot be instantiated and similar like Abstract class. Interface is a blueprint of a class and it represents Is-A-Relationship.

I myself just tried this sample program:

interface Printable{
void print();
}
public class A implements Printable{
public void Print(){
 System.out.println("Prints..");
}
public static void main(String args[]){
 A obj=new A();
 obj.print();
}
}

Output is,

Compiling the source code....
$javac A.java 2>&1
A.java:4: error: A is not abstract and does not override abstract method print() in Printable
public class A implements Printable{
^
A.java:10: error: cannot find symbol
obj.print();
^
symbol: method print()
location: variable obj of type A
2 errors

What does it mean by "A is not abstract and cannot override abstract method print()"?

What mistake I have done here? So I can learn from my mistakes!

halfer
20.2k20 gold badges111 silver badges208 bronze badges
asked Nov 24, 2013 at 5:57
6
  • 4
    Print method should be in lower case Commented Nov 24, 2013 at 5:58
  • 2
    Java is case sensitive. Print and print are not the same. Commented Nov 24, 2013 at 5:58
  • @DGomez you should post as answer shouwing an example. Commented Nov 24, 2013 at 5:59
  • 1
    "Interface is a blueprint of a class and it represents Is-A-Relationship." This is incorrect. If a type has a strong "is a" relationship with an existing class, then that is the right time to be thinking about inheritance. Interfaces are used to express a common contract that can be shared by classes even if they are not related by hierarchy. For interfaces, the contract is the thing ... and no "is a" relationship is required. Commented Nov 24, 2013 at 6:13
  • @scottb So, it means Interface indicates the common contract so that can share the abstract methods by any other classes? Commented Nov 24, 2013 at 6:24

3 Answers 3

4
void print()

vs

void Print()

It's a capital mistake.

You are getting the error

A is not abstract and does not override abstract method print()

Because abstract classes can implement an interface without actually implementing the methods it defines.

See here:

In the section on Interfaces, it was noted that a class that implements an interface must implement all of the interface's methods. It is possible, however, to define a class that does not implement all of the interface methods, provided that the class is declared to be abstract.

The other part of the error message is from the above "capital" mistake.

answered Nov 24, 2013 at 5:59
Sign up to request clarification or add additional context in comments.

3 Comments

Oh I am sorry, this minor mistake I have not found it. Thanks !
I referred the link which you have mentioned. What does it mean and how does it looks?"When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract."
What is unclear to you? It's exactly as it says there: the eventual subclass that you want to instantiate must implement all interface methods and all abstract methods. These can be implemented in superclass during the chain, but if there are any abstract methods or unimplemented methods left, you'll have to make the class abstract and provide another subclass that does implement them.
0

The error is very clear

A.java:4: error: A is not abstract and does not override abstract method **print()** in Printable

As you see the method is print() not Print()

answered Nov 24, 2013 at 6:01

Comments

0

please check your spell of Print(). it is in lowercase in interface

answered Nov 24, 2013 at 6:29

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.