Which of these statements follows proper naming conventions for or in a Java program?
a. class karateClass {~}
b. class car {~}
c. int HeightOfTriangle;
d. int GRADEONTEST = 90;
e. private static final double PI_TO_SIX_DIGITS = 3.14159;
Hi, I hope you are doing well.
Below given are the proper naming conventions in java program:
a.) class karateClass {~}
Reason: Class name must start with lowercase and if it contain more than one word than from second word the first letter must of that word be capital or uppercase.
c.) int HeightOfTriangle;
Reason: Variable name must start with lowercase or uppercase but should not use dollar($), underscore(_) or ampersand(&) at starting of the name.
e.) private static final double PI_TO_SIX_DIGITS = 3.14159;
Reason: In this there is final and static keyword which defines that this is a constant so the constant must be in uppercase and can use underscore between two words.
NOTE: Remaining option does not follow the naming convention of java as we can see in option (b) it contains class name which is in lowercase it must start with uppercase and in option (d) the integer must be in lowercase or the first letter of the word can be uppercase but whole word can not be if we do so than there will be complexity to differentiate the constant value and other variables.
Get Answers For Free
Most questions answered within 1 hours.