Cycle Test - 4 Answer Key
Cycle Test - 4 Answer Key
Section B
1. Tokens: Tokens are the smallest elements of a program that are meaningful to the compiler.
Examples: keywords, identifiers, literals, operators, and separators.
Keywords: Keywords are reserved words in a programming language that have a predefined
meaning. They cannot be used for variable names.
Examples: include class, public, void, etc.
2. Constant vs Variable:
o A constant is a value that cannot be changed during the execution of a program. It is
declared using the final keyword in Java. Example: final int MAX_SIZE = 100;
o A variable is a storage location that holds a value that can be changed during the
execution of a program.
Example: int score = 50;
3. Valid and Invalid Identifiers:
o %myname - Invalid (cannot start with a special character)
o _hi123 - Valid (starts with an underscore)
o hi alexa - Invalid (contains a space)
o public - Invalid (keyword)
o by5 - Valid (starts with a letter)
Section C
Java Program:
class StudentMarks
{
String name;
int n1, n2, n3;
double avg;
void input()
{
name=”Ramesh”;
n1=10,n2=20,m3=40;
}
void average()
{
avg = (n1 + n2 + n3) / 3.0;
}
void display()
{
System.out.println("Student Name: " + name);
System.out.println("Average Marks: " + avg);
}
public static void main(String[] args)
{
StudentMarks student = new StudentMarks();
student.input();
student.average();
student.display();
}
}