SEE THE EDIT HALFWAY DOWN THE POST.
I'm new to java and all the formal declarations of inheritance are getting me a little confused.
I have a interface like so:
public interface A{
public void one();
public void two();
}
and then I have two classes like so:
public class B implements A{
private int num;
public void one(){
...
}
public void two(){
...
}
public B(){
this.num = 1;
}
}
public class C extends B{
public C(){
super();
}
}
then I have a driver class like so:
public class Driver{
public static void main(String [] args){
A a_array[] = new A[5];
for(int i=0; i<6; i++){
if(i%2==0){
a_array[i] = new B();
}
else{
a_array[i] = new C();
}
}
}
}
Basically, given an array of interfaces I am trying to implement various classes that implement that interface.
Now my guess is there are several things wrong with this implementation, but I seem unable to sniff them out. Primarily right now I am getting the error 'B() is not abstract and does not implement method one()'.
EDIT:
alright lets try this... the interface:
public interface Shape{
public double calcAread();
public double calcPerimeter();
}
the implementing class:
public class Rectangle implements Shape{
private double length;
private double width;
public double calcArea(){
return this.length*this.width;
}
public double calcPerimeter(){
return (this.length*2)+(this.width*2);
}
public Rectangle(double length, double width){
this.length=length;
this.width=width;
}
// then some other methods including the set methods
}
the extending class:
public class Square extends Rectangle{
public Square(){
super();
}
public Square(double sideLength){
super.setLength(sideLength);
super.setWidth(sideLength);
}
// some more methods
}
I can't think of very much more that would be useful other than to mention that there are other inheriting and extending classes off of these but they follow exactly the same design and sentax.
No errors when I compile shape, but the 'Rectangle is not abstract and does not override abstract method calcAread() in Shape' error is tripped when I compile the Rectangle class.
Hopefully this will be more enlightening.
Thanks
Class[] interfaces = { SomeInterface.class, SomeOtherInterface.class }. You're talking about an array of A, where A is an interface.