Java enum method -


the following code has no problem compiling , running. question use of public int getvalue(int bid) [ not getvalues(int bid) ? how call method?

package com.main; public class bridge {      public enum suites{         club(20), dimond(20), hearts(30), spades(40){              public int getvalue(int bid){                 return ((bid-1)*30)+40;             }         };         private int points;         suites(int points){             this.points = points;          }          public int getvalues(int bid){             return points*bid;         }      }      public static void main(string[] args){         system.out.println(suites.club.getvalues(3));         system.out.println(suites.hearts.points);         system.out.println(suites.values());     }  } 
 out put :  60 30 [lcom.main.bridge$suites;@2a139a55 

the use case getvalue method specified spades if method same , and signature specified suites enum, e.g. this:

public class test {      public enum suites {         club(20),         dimond(20),         hearts(30),         spades(40) {             @override             public int getvalue(int bid) {                 return ((bid - 1) * 30) + 40;             }         };         private int points;          suites(int points) {             this.points = points;          }          public int getvalue(int bid) {             return bid;         }          public int getvalues(int bid) {             return points * bid;         }      }      public static void main(string[] args) {         (suites suite : suites.values()) {             system.out.println(suite.name() + ": getvalue: " + suite.getvalue(1));         }     } } 

this output

club: getvalue: 1 dimond: getvalue: 1 hearts: getvalue: 1 spades: getvalue: 40 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -