Try it. Methods removed for simplicity
public class Test1 { public static void main( String [] args) { MyTriangle h1 = new MyTriangle(); } } class MyTriangle implements Triangle{ int side1; int side2; int side3; public MyTriangle(){ this.side1 = 1; this.side2 = 2; this.side3 = 3; } } interface Triangle{}
You have not entered your full code, I assume that your code should look something like this.
Then you must create an instance for your main class before creating an instance for your triangle, as shown below.
public class Test{ class MyTriangle { int side1,side2,side3; public MyTriangle() { this.side1 = 3; this.side2 = 4; this.side3 = 5; } } public static void main(String[] args) { MyTriangle h1 = new Test(). new MyTriangle();
source share