Click here to watch in Youtube :
https://www.youtube.com/watch?v=JGSYkP0Jig0&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
![]() |
Java Tutorial: Enum in java[How to define a constructor and method in enum - Company] |
enum Company
{
PAYPAL(101), GOOGLE(201), YAHOO(301);
private int companyCode;
private Company(int companyCode)
{
this.companyCode = companyCode;
}
public int getCompanyCode()
{
return companyCode;
}
}
EnumDemo.javapublic class EnumDemo
{
public static void main(String[] args)
{
Company[] companyArray= Company.values();
for (Company cName : companyArray)
{
System.out.println("Company Code: " + cName.getCompanyCode()
+ " - Company Name: " + cName);
}
}
}
OutputCompany Code: 101 - Company Name: PAYPAL
Company Code: 201 - Company Name: GOOGLE
Company Code: 301 - Company Name: YAHOO
Click the below link to download the code:
No comments:
Post a Comment