How to run this code without main method (short program) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to run this code without main method (short program)

NO ERRORS just cant run public class Fish { String typeOfFish; int friendliness; public Fish(){ this.typeOfFish = "Unknown"; friendliness = 3; } public Fish(String t, int f){ typeOfFish = t; friendliness = f; } int getFriendliness(){ return friendliness; } Fish amber = new Fish("Amber",5); Fish james = new Fish(); Fish nicestFish(Fish a, Fish b){ if(a.getFriendliness()> b.getFriendliness()) return a; else return b; } }

4th Apr 2020, 9:13 PM
Dzondzula
Dzondzula - avatar
1 Answer
+ 1
You can't run your code without main method. public class Fish{ //your Fish class } : //TestFish which works with the Fish class public class TestFish{ public static void main(String[] args){ //Here you can create Fish objects and see if all methods works //Fish amber and Fish james goes here }
4th Apr 2020, 9:28 PM
Denise Roßberg
Denise Roßberg - avatar