Question subject: java abstract class,concrete class and interface
Posted: Thu Jan 22, 2009 5:22 pm
Joined: Thu Jan 22, 2009 3:52 am Posts: 4 Has thanked: 0 time Have thanks: 0 time
what is the meaning of abstract class,concrete class and interface ? can give example of each.
thanks
Last edited by msi_333 on Thu Jan 22, 2009 8:09 pm, edited 1 time in total.
edit title
msi_333
Question subject: Re: Pls Help me..
Posted: Thu Jan 22, 2009 8:09 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
1. In Java there is no multipliable inheritance like in C++ .But you can implement more thank one interface . The interface methods are all abstract , this means contain no body ,and all properties are public static final (Means can't be changed later) . In interface you just say what is the class but don't say how to do it . Methods of interface are public and abstract by defaults and you don't need write the modifiers. interface can extend one or more interfaces .
Example
Code:
interface shape { public abstract void draw();
}
Here a class circle implements the shape interface.
Code:
class shape implements shape { public void draw() { // Draw body }
}
2. Abstract class can have implemented methods and others not , you can't have an abstract method in non abstract class. you have alway to remember to that abstract methods end with semicolon . example
Code:
public abstract class Vehicle { private String type; public abstract void goUpHill(); // Abstract method public String getType() { // Non-abstract method return type; } } public abstract class Car extends Vehicle { public abstract void goUpHill(); // Still abstract public void doCarThings() { // special car code goes here } } public class Mini extends Car { public void goUpHill() { // Mini-specific going uphill code } }
i hope i helped you .
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
Bluerose
Question subject: Re: java abstract class,concrete class and interface
Posted: Sat Mar 21, 2009 4:53 am
Joined: Fri Mar 20, 2009 4:03 am Posts: 21 Location: Indonesia Has thanked: 0 time Have thanks: 0 time
Thank you for this information. I was facing an exam and the difference of these abstracts and interfaces confuses me a bit and now i am cleared. Thank you for the question raised by Dummies in Java and the explanation as well from msi_333