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
-
0
-
NULL
-
Depends on the scale and precision of the datatype.
-
Without initialization, a variable cannot be used in the executable section of the block.
B
Correct answer
Explanation
In PL/SQL, any scalar variable (NUMBER, VARCHAR2, DATE, etc.) that is declared but not initialized automatically gets NULL as its initial value. Option A is incorrect because 0 would need explicit initialization. Option C is wrong because NULL behavior is consistent across scale/precision. Option D is false because uninitialized variables can be used - they'll just be NULL until assigned.
A
Correct answer
Explanation
REF cursors in PL/SQL are cursor variables that can be passed between procedures and functions. Unlike static cursors, REF cursors are dynamic and can be opened for different queries at runtime and shared across program units.
-
Arrays
-
Varrays
-
Indexes
-
Synonyms
B
Correct answer
Explanation
VARRAYs (variable-size arrays) require a maximum size to be specified at declaration time. Unlike nested tables which are unbounded, VARRAYs have a fixed upper bound. Arrays and indexes are different concepts, and synonyms are database objects unrelated to size constraints.
-
Clicking Step Over to step over the execution of the subprogram
-
Opening the Stack panel, selecting the previous stack frame, and clicking Go
-
Clicking Step Out to resume stepping through code after the subprogram is called
-
HE cannot do this in the same debug session. He should click Stop, set a breakpoint immediately after the subprogram code is called, and run the form in debug mode again
A
Correct answer
Explanation
Step Over executes the entire subprogram without stepping through its internal lines, then returns control to the line immediately after the subprogram call. This is exactly what SMITH needs when he realizes the error is in code after the subprogram, not within it.
-
catch(X x) can catch subclasses of X where X is a subclass of Exception.
-
The Error class is a RuntimeException.
-
Any statement that can throw an Error must be enclosed in a try block.
-
Any statement that can throw an Exception must be enclosed in a try block.
A
Correct answer
Explanation
Option A is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well.
Option B is wrong. The error class is a subclass of Throwable and not RuntimeException.
Option C is wrong. You do not catch this class of error.
Option D is wrong. An exception can be thrown to the next method higher up the call stack.
-
It is used to start a session.
-
It is used to destroy the session.
-
It is used to store a session variable.
-
Both (1) and (3)
-
None of the above
C
Correct answer
Explanation
Yes, $_SESSION variable is used to store or retrieve the session variable.
-
A try statement must have at least one corresponding catch block.
-
Multiple catch statements can catch the same class of exception more than once.
-
An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.
-
Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.
D
Correct answer
Explanation
A is wrong. A try statement can exist without catch, but it must have a finallystatement.
B is wrong. A try statement executes a block. If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause. If that catch block completes normally, then the try statement completes normally.
C is wrong. Exceptions of type Error and RuntimeException do not have to be caught, only checked exceptions (java.lang.Exception) have to be caught. However, speaking of Exceptions, Exceptions do not have to be handled in the same method as the throw statement. They can be passed to another method.
If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances:
An exception arising in the finally block itself.
The death of the thread.
The use of System.exit()
Turning off the power to the CPU.
I suppose the last three could be classified as VM shutdown.
D
Correct answer
Explanation
(1) causes two compiler errors ( '[' expected and illegal start of expression) because the wrong type of bracket is used, ( ) instead of [ ]. The following is the correct syntax:float[ ] f = new float[3];
(2) causes a compiler error ( '{' expected ) because the array constructor does not specify the number of elements in the array. The following is the correct syntax: float f2[ ] = new float[3];
(3), (4), and (5) compile without error.
-
In an assert statement, the expression after the colon ( : ) can be any Java expression.
-
If a switch block has no default, adding an assert default is considered appropriate.
-
In an assert statement, if the expression after the colon ( : ) does not have a value, the assert's error message will be empty.
-
It is appropriate to handle assertion failures using a catch clause.
B
Correct answer
Explanation
Adding an assertion statement to a switch statement that previously had no default case is considered an excellent use of the assert mechanism.
Option A is incorrect because only Java expressions that return a value can be used. For instance, a method that returns void is illegal.
Option C is incorrect because the expression after the colon must have a value.
Option D is incorrect because assertions throw errors and not exceptions, and assertion errors do cause program termination and should not be handled.
-
typedef
-
unsigned
-
union
-
mutable
-
none of the above
E
Correct answer
Explanation
All of the above are keywords in C++.
-
boolean
-
void
-
public
-
Button
C
Correct answer
Explanation
In Java, 'public' is an access modifier (controls visibility), not a return type. Return types specify what data type a method returns: void (returns nothing), boolean (returns true/false), or any class type like Button. Access modifiers like public, private, protected are separate concepts that specify who can access the method, not what it returns.
-
The default char data type is a space( ' ' ) character.
-
The default integer data type is 'int' and real data type is 'float'
-
The default integer data type is 'long' and real data type is 'float'
-
The default integer data type is 'int' and real data type is 'double'
D
Correct answer
Explanation
Java has default types for numeric literals. Integer literals (like 42) are int by default. Floating-point literals (like 3.14) are double by default. Option D correctly states both defaults.
-
Private
-
Protected
-
Public
-
Friend
-
Both private and public
D
Correct answer
Explanation
This is not a visibility mode in C++ instead it is a type of function that can act as friend to any class and access its data members.
-
Arithmetic operator
-
Relational operator
-
Conditional operator
-
Comparison operator
-
Addition operator
C
Correct answer
Explanation
This operator cannot be overloaded in C++ as it consist of (?:) symbol and requires a condition and two options.
-
Memory allocation function
-
Inline function
-
Member function
-
Default function
-
Friend function
B
Correct answer
Explanation
This is the function in C++ used for performing short term calculation and consisting of one or two statements only.