0% found this document useful (0 votes)
8 views1 page

Cycle Test - 4 Answer Key

The document contains a series of programming questions and answers, focusing on Java concepts such as tokens, constants vs variables, and valid identifiers. It also includes a sample Java program that calculates and displays a student's average marks. Key topics covered include keywords, the definition of tokens, and examples of valid and invalid identifiers.

Uploaded by

darlinmary82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Cycle Test - 4 Answer Key

The document contains a series of programming questions and answers, focusing on Java concepts such as tokens, constants vs variables, and valid identifiers. It also includes a sample Java program that calculates and displays a student's average marks. Key topics covered include keywords, the definition of tokens, and examples of valid and invalid identifiers.

Uploaded by

darlinmary82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Section A

1. Answer: b) byte, char, int, double


2. Answer: c) Separators
3. Answer: d) Floating point, boolean, String
4. Answer: d) true (since true is a literal, not a keyword)

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();
}
}

You might also like