Google

Wednesday, September 3, 2008

Java - extends Class

Extends use to calling other class method that you need to use in the main class..
However, each time only one class can be extends..
Here is an example of extends class

----------Condidate Class--------------------
public class Candidate
{
private static String[] candidateList;

public Candidate(){
candidateList = new String[3];
}

public static String[] getCandidate(){

return candidateList;
}
}


--------------Main Class-------------------

public class VoteCandidate extends Candidate{

//In default constructor must super() the class you extends
//which is the default constructor in extends class
//In this examples, when u call super(), it mean you create
//candidateList = new String[3];

public VoteCandidate(){
super();
}


}

No comments: