What is enum? We can use final also. What is difference between enum and final? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is enum? We can use final also. What is difference between enum and final?

21st Jul 2016, 2:28 PM
Muhammad Sajid
Muhammad Sajid - avatar
3 Answers
+ 2
Final : a value is set final to make it a constant, that is it can never be changed. Enum : We create a datatype just like int, float, etc., and also define, what values the user can enter. Eg: final b=10; Any action on b will never change its value enum Month {Jan,May,Apr}; Month a; a is a variable of datatype Month and can hold only the values specified. Either Jan or May or Apr
23rd Jul 2016, 3:51 PM
Jo Thomas
Jo Thomas - avatar
+ 1
Enums are special classes used to define constants and normally used for things like days of the week, planets , point of compass etc. And also enums are already final and static. For more information visit tutorialspoint or stack overflow
21st Jul 2016, 3:01 PM
Ousmane Diaw
0
final gets one value and that can't be changed but we can declare final and set it's value later, like final int a; //code a=7; enums are all predefined and there is few of them, as Ousmane said. if u have 1 or 2 variables use final in any case..
22nd Jul 2016, 4:39 PM
Petar Suvajac
Petar Suvajac - avatar