public class Shape {
public static void main (String[] args) {
Circle c = new Circle(5);
System.out.println (c.getArea());
c.setColour("Green");
System.out.println (c.getColour());
}
}
interface Colour {
String getColour();
void setColour (String colour);
}
abstract class Shapes implements Colour {
abstract double getArea();
private String colour = "Red";
public String getColour() {
return colour;
}
public void setColour(String colour) {
this.colour = colour;
}
}
class Circle extends Shapes {
private int radius;
public Circle(int radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
}
I have attempted a Swift Solution the code is below
import Cocoa
protocol Colour {
var colour: String { get set }
func getColour() -> (String)
func setColour(colour: String)
}
class Shape: Colour {
var colour: String = "Red"
init(colour: String) {
self.colour = colour
}
func getColour() -> (String) {
return colour
}
func setColour(colour: String) {
self.colour = colour
}
func getArea() -> Double {
return 0.0
}
}
class Circle: Shape {
let radius: Double
init(radius: Double) {
self.radius = radius
}
override func getArea() -> Double {
return radius * radius * Double.pi
}
}
I have written code to create an interface 'colour', a super class 'shape' and a subclass 'Circle'. The aim is to learn more about inheritance and multiple inheritance as a new programmer. The java code works as intended.
But i am getting an error " 'super.init' isn't called on all paths before returning from initializer" with the above Swift code. As I am newer to swift and multiple inheritance I am not sure how to correct this error.
How I can correct this?