Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query in Abstract classes and interfaces

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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() {
System.out.println("Printed");
}
}

public class Four extends AbstractFourOne implements I1{

public void add() {
System.out.println("Add");
}
/*
public void subtract() {
System.out.println("Subtract");
}
*/
public static void main(String[] args) {
new Four().add();
new Four().subtract();
AbstractFourOne.printIt();
}
}

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

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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't repost the same question, I moved the other one to the correct forum.

Dave
 
    Bookmark Topic Watch Topic
  • New Topic