• Post Reply Bookmark Topic Watch Topic
  • New Topic

Query in abstract classes and interfaces.  RSS feed

Roopa Prabhu
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take a look at this code.

interface I1 {
public void add();
public void subtract();

abstract class AbstractFourOne {
abstract public void add();

public void subtract() {
System.out.println("Subtract from abstract class...");

static public void printIt() {

public class Four extends AbstractFourOne implements I1{

public void add() {
public void subtract() {
public static void main(String[] args) {
new Four().add();
new Four().subtract();

This code neither gives a compile time error nor a run time exception. Instead it shows the output:
Subtract from abstract class...

Why doesn't it as for implementation code for the subtract method of the I1 interface although there is no relationship between I1 and AbstractFourOne.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!