Computer Knowledge

Programming Fundamentals

2,381 Questions

Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.

Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references

Programming Fundamentals Questions

Multiple choice technology programming languages
  1. int $x;
  2. int 123;

  3. int _123;

  4. int #dim;

  5. int %percent;

  6. int central_sales_region_Summer_2005_gross_sales;

Reveal answer Fill a bubble to check yourself
A,C,F Correct answer
Explanation

In Java, valid identifiers can start with a letter, an underscore (_), or a currency symbol (like $). Subsequent characters can also include digits. Identifiers cannot start with a digit, and symbols like # or % are not allowed.

Multiple choice technology programming languages
  1. If only line 1 is removed the code compiles.

  2. If only line 3 is removed the code compiles.

  3. If only line 5 is removed the code compiles.

  4. If lines 1 and 3 are removed the code compiles

  5. If lines 1, 3 and 5 are removed the code compiles.

Reveal answer Fill a bubble to check yourself
C,E Correct answer
Explanation

Java doesn't allow enum declarations inside methods (line 5). Removing line 5 eliminates this syntax error, allowing compilation. Option C is correct. Removing all three enum declarations (lines 1, 3, 5) leaves only the class and method structure without any nested enums, which is valid Java - option E is correct. Options A, B, and D are incorrect because they still include the method-local enum declaration on line 5.

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Integer division by zero (e.g., 5/0) throws ArithmeticException, unlike floating-point division by zero (e.g., 5.0/0) which produces Infinity. This is because integer arithmetic cannot represent infinity - the operation is undefined for integers and must signal an error.

Multiple choice technology programming languages
  1. Compiler Error

  2. Exception

  3. I am in Constructor

  4. Message Hello

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The main method is not declared static, which is required by the JVM. When you try to run this class, the JVM cannot find a valid entry point and will throw an exception at runtime stating that the main method must be static.

Multiple choice technology programming languages
  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When comparing primitives of different numeric types, Java applies binary numeric promotion - the smaller type is automatically promoted (widened) to the larger type. For example, comparing int and long promotes the int to long. No explicit cast is needed.

Multiple choice technology programming languages
  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, when comparing two different primitive numerical types (such as int and double), binary numeric promotion automatically promotes the operand with the smaller range or precision to match the larger/wider type before the comparison is executed, preventing compile errors.

Multiple choice technology programming languages
  1. 1,3

  2. 2,3

  3. Compilation Error

  4. Exception

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To solve this question, the user needs to know the basics of boolean expressions and how they work in Java programming. They also need to understand the concept of conditional statements.

Let's go through each option and explain why it is right or wrong:

The code starts by initializing the variable x to 5, and the boolean variables b1 and b2 to true and false, respectively.

The first conditional statement checks if the value of x is equal to 4 and if b2 is false. Since neither condition is true, the code skips the first print statement and moves on to the second one.

The second print statement prints "2" to the console.

The second conditional statement assigns the value true to b2 and then checks if b1 is also true. Since both conditions are true, the code executes the third print statement, printing "3" to the console.

Therefore, the output of the program is:

2 3

So, the correct answer is:

The Answer is: B

Multiple choice technology programming languages
  1. FIFO

  2. LIFO

  3. both (a) and (b)

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A stack follows LIFO (Last In, First Out) - the last element pushed onto the stack is the first one popped off. This is like a stack of plates where you add and remove from the top. FIFO describes a queue, not a stack.

Multiple choice technology programming languages
  1. For loop

  2. While loop

  3. if loop

  4. All the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The break statement is used to exit from loops (for, while, do-while) and switch statements. It cannot be used with if statements because if is a conditional statement, not a loop. 'if loop' is incorrect terminology but the meaning is clear.

Multiple choice technology programming languages
  1. int

  2. public

  3. button

  4. void

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The keyword public is an access modifier in languages like Java, C++, and C#, not a data type. Primitive types like int, object/component classes like button, and return types like void are all valid data types or type descriptors, making public the correct choice.

Multiple choice technology programming languages
  1. w var1

  2. w this.var1

  3. w ..var1

  4. w ..#var1

  5. w (classname).var1

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In Cache ObjectScript, the syntax ..#var1 is used to reference class parameters with indirection. The ## (double dot) operator provides access to class parameters, while the # symbol allows for parameter reference. Option w (write) is the command to output the value, making w ..#var1 the correct syntax for writing a class parameter value.