Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

java abstract class,concrete class and interface

Thu Jan 22, 2009 5:22 pm

what is the meaning of abstract class,concrete class and interface ?
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 always 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
}
}
 



Last edited by DrRakha on Fri May 31, 2013 12:59 pm, edited 3 times in total.
Reason: edit title

Post a reply
  Related Posts  to : java abstract class,concrete class and interface
 The difference between an Interface and an Abstract class     -  
 concrete class     -  
 what is a concrete class     -  
 What is an Abstract Class? !!!     -  
 make abstract class     -  
 how to Define abstract class in php     -  
 why cant instantiate an abstract class     -  
 Is garbageCollector a Class or interface?     -  
 Define class helper class to check the method existance     -  
 relationship between the Canvas class and the Graphics class     -  

Topic Tags

Java OOP