Computer Knowledge
Programming Fundamentals
2,611 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
D
Correct answer
Explanation
In Java, 'public', 'static', and 'void' are reserved keywords that have special meaning in the language. 'main' is NOT a reserved keyword - it's simply the name of a method that is commonly used as the entry point for Java applications, but you could technically name a method 'main' in any class.
-
void method1 { /* ... */ }
-
void method2() { /* ... */ }
-
void method3(void) { /* ... */ }
-
method4() { /* ... */ }
B
Correct answer
Explanation
In Java, a valid method declaration requires a return type (or void), a method name, and a parameter list enclosed in parentheses, followed by the method body. void method2() { } correctly satisfies these syntax rules.
B
Correct answer
Explanation
Generic code problems are handled at compile-time, not runtime. Java uses type erasure where generic type information is removed during compilation. By the time the code runs, generic types are replaced with their bounds or Object, making runtime generic type checking impossible.
-
{{}} is a valid statement block
-
{ continue; } is a valid statement block
-
block: { break block; } is a valid statement block
-
block: { continue block; } is a valid statement block
A,C
Correct answer
Explanation
{{}} is valid - it's a nested empty block. { continue; } is invalid because continue must be inside a loop. block: { break block; } is valid - labeled break can exit any labeled block. block: { continue block; } is invalid because continue requires an enclosing loop, not just a labeled block.
-
DUMP
-
CANCEL
-
ABEND
-
WARNING
C
Correct answer
Explanation
In JES2, the LINES parameter specifies output line limits and can be used with values like DUMP (dump output), CANCEL (cancel output), and WARNING (issue warning message). ABEND is not used with LINES - it's a separate job termination action.
-
(B) & (C)
-
(E)
-
(A) & (C)
-
(D)
C
Correct answer
Explanation
Java keywords are reserved words with special meaning. 'switch' and 'default' are valid keywords. 'integer' is not a keyword (int is the primitive type). 'boolean' is a keyword (primitive type). 'object' is not a keyword (Object is a class).
-
(D) & (E)
-
(A), (D) & (E)
-
(D)
-
(C), (D) & (E)
B
Correct answer
Explanation
In Java, NULL (should be null), extended (should be extends), and string (String is a class) are not keywords. 'implements' and 'protected' are valid Java keywords. Option B correctly identifies the three items that are not keywords.
-
(B) & (C)
-
b. (E)
-
c. (A) & (C)
-
d. (D)
C
Correct answer
Explanation
In Java, 'switch' and 'default' are valid keywords. 'integer' is not a keyword (int is), 'boolean' is a valid keyword (primitive type), and 'object' is not a keyword (Object is a class). Option C correctly identifies the keywords.
-
(D) & (E)
-
b. (A), (D) & (E)
-
c. (D)
-
d. (C), (D) & (E)
B
Correct answer
Explanation
In Java, implements and protected are keywords. NULL (all uppercase) is not a keyword (the literal is lowercase null), extended is not a keyword (the keyword is extends), and string is not a keyword (the class is String). Thus, (A), (D), and (E) are not keywords.
-
sizeof
-
::
-
:?
-
All the Above
D
Correct answer
Explanation
C++ prohibits overloading the sizeof operator (language built-in for memory size), scope resolution operator :: (fundamental to language syntax), and ternary operator ?: (conditional operator has special syntax rules). These operators are part of the core language and their behavior is fixed by the specification.
-
zero
-
NULL
-
one
-
No Entry in vtable
B
Correct answer
Explanation
Compilers typically set the vtable entry for a pure virtual function to NULL. This ensures that attempting to call a pure virtual function directly (without overriding) results in a predictable error. The NULL entry indicates no implementation is available in this class. Abstract classes cannot be instantiated precisely because they have such NULL vtable entries.
-
NVL
-
NULLIF
-
DECODE
-
COALESCE
A,B,D
Correct answer
Explanation
NVL, NULLIF, and COALESCE are standard SQL functions designed specifically to handle NULL values. While DECODE can handle NULLs in its logic, it is primarily a conditional transformation function rather than a dedicated NULL-handling function like the others.
-
Write Once, Run Anywhere
-
Read Once, Write Anywhere
-
Read Once, Run Anywhere
-
Write Twice, Run Once
A
Correct answer
Explanation
Java's core promise is 'Write Once, Run Anywhere' (WORA), enabled by the Java Virtual Machine (JVM). This means compiled Java code can run on any platform supporting JVM without recompilation. The other options are incorrect.
-
Compilation Error - Struct cannot be defined without a name
-
193149
-
Compilation Error - Struct cannot be defined inside a Function
-
Some Random Number
B
Correct answer
Explanation
In C, you can define an anonymous structure and instantiate it immediately (struct { ... } var;). This is valid inside a function, and the code will print the assigned integer value 193149.
-
Header
-
Declarative
-
Executable
-
Exception
D
Correct answer
Explanation
PL/SQL blocks have four sections: Header (optional, for named blocks), Declarative (DECLARE section for variables, types, cursors), Executable (BEGIN...END for main logic), and Exception (EXCEPTION section for error trapping and handling). The Exception section specifically contains functions and handlers for errors.