Computer Knowledge

Programming Languages and Compilers

2,284 Questions

Programming languages and compilers involve the rules, syntax, and semantics used to write and execute software programs. Key areas include scripting languages, object oriented concepts, and parsing algorithms like top down parsers. Practice these computer science questions to build proficiency for technical and computer knowledge exams.

Object oriented languagesScripting languagesCompilers and parsersProgramming syntax

Programming Languages and Compilers Questions

Multiple choice technology databases
  1. a) Packages can be nested.

  2. b) You can pass parameters to packages.

  3. c) A package is loaded into memory each time it is invoked.

  4. d) The contents of packages can be shared by many applications.

  5. e) You can achieve information hiding by making package constructs private.

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

Packages are designed to be shared - their contents (specification and body) can be used by many applications and users simultaneously (option D). Information hiding is achieved by declaring constructs in the package body only, making them private and inaccessible outside the package (option E). Packages cannot be nested (option A). Parameters are passed to procedures/functions within packages, not to packages themselves (option B). Packages are loaded once per session and cached, not reloaded each invocation (option C).

Multiple choice technology databases
  1. a)Yes

  2. b)No

  3. c)

  4. d)

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

Yes, hiding private constructs in the package body is a key advantage of packages. This implements information hiding and encapsulation - the package specification exposes only what users need, while implementation details remain private and inaccessible. This prevents users from depending on or misusing internal implementation details, allowing the package developer to change the internal logic without affecting users.

Multiple choice technology programming languages
  1. x=1 and y=1

  2. x=1 and y=2

  3. x=2 and y=2

  4. x=2 and y=1

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

The post-increment operator x++ first returns the current value of x (which is 1), then increments x to 2. So y receives 1 (the original value), and x becomes 2 after the operation. This is a fundamental concept of post-increment vs pre-increment (++x) operators in Java.

Multiple choice technology programming languages
  1. x=1 and y=1

  2. x=2 and y=2

  3. x=1 and y=2

  4. x=2 and y=1

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

This is identical to question 130241. The post-increment operator x++ first returns the current value (1) to y, then increments x to 2. Result: x=2, y=1. The post-increment operator's behavior is that it returns the original value before performing the increment.

Multiple choice technology programming languages
  1. 10

  2. 0

  3. Garbage Value

  4. Compile time error

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

This code causes a compile-time error because local variable x is not initialized before being used. Even though x is assigned inside the if block, the compiler cannot guarantee that the if condition (y>0) will be true at runtime. Java requires local variables to be definitely assigned before use. The compiler sees a path where x could remain uninitialized.

Multiple choice technology programming languages
  1. A free implementation of PostScript

  2. A printing management tool

  3. A program for converting files to PostScript

  4. A free interpreter of PostScript

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

GhostScript is a free, open-source interpreter for the PostScript page description language. It reads and processes PostScript files, converting them to various formats or rendering them for printers and displays. It's not a full implementation or management tool, but an interpreter that processes PostScript commands.

Multiple choice technology programming languages
  1. a) Only local or packaged sub programs can be overloaded.

  2. b) Overloading allows different functions with the same name that differ only in their return types.

  3. c) Overloading allows different subprograms with the same number, type and order of the parameter.

  4. d) Overloading allows different subprograms with the same name and same number or type of the parameters.

  5. e) Overloading allows different subprograms with the same name but different in either number or type or order of parameter.

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

Package overloading in Oracle allows multiple subprograms with the same name if they differ in their parameter signatures. Only local or packaged subprograms can be overloaded (standalone subprograms cannot). The key rule is: same name but different in number, type, or order of parameters. Return types alone are insufficient for overloading - two subprograms differing only in return type would cause ambiguity.

Multiple choice technology programming languages
  1. a) Packages can be nested.

  2. b) You can pass parameters to packages.

  3. c) A package is loaded into memory each time it is invoked.

  4. d) The contents of packages can be shared by many applications.

  5. e) You can achieve information hiding by making package constructs private.

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

Oracle packages support information hiding through private constructs (package body vs specification) and enable code sharing across applications. Packages cannot be nested, you cannot pass parameters to packages themselves (only to their subprograms), and packages are loaded once per session then cached - not reloaded on each invocation. These design features make packages efficient and modular.

Multiple choice technology
  1. Compilation fails due to an error in line 23.

  2. Compilation fails due to an error in line 29.

  3. A ClassCastException occurs in line 29.

  4. A ClassCastException occurs in line 31.

  5. The value of all four objects prints in natural order.

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

When Arrays.sort() is called on an array containing mixed object types (Integer, String, Boolean), it will fail at runtime with ClassCastException because these types are not mutually Comparable. The sort method attempts to compare elements but cannot compare different types. The exception occurs at line 29 when sort() tries to compare incompatible types during the sorting process.

Multiple choice technology
  1. 0.0

  2. Compilation fails.

  3. A ParseException is thrown by the parse method at runtime.

  4. A NumberFormatException is thrown by the parse method at runtime.

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

Variable f is declared inside the try block (line 13), so it's not in scope when accessed in the finally block (line 17). Variables in try-catch-finally must be declared outside the try block to be accessible in finally.

Multiple choice technology
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes and prints "running".

  4. The code executes and prints "runningrunning".

  5. The code executes and prints "runningrunningrunning".

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

t.run() calls the method directly in the main thread (twice), printing 'running' each time. t.start() creates a new thread that also prints 'running'. Total: 3 'running' prints concatenated as 'runningrunningrunning'.

Multiple choice technology
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes and prints "StartedComplete"

  4. The code executes and prints "StartedComplete0123".

  5. The code executes and prints "Started0123Complete".

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

t.start() begins the thread, 'Started' prints, t.join() waits for thread completion (printing 0123), then 'Complete' prints. The join() ensures the main thread waits for t to finish before proceeding.

Multiple choice technology
  1. harrier

  2. shepherd

  3. retriever

  4. Compilation fails

  5. retriever harrier

  6. An exception is thrown at runtime

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

The syntax 'case default:' is invalid. In switch statements, the default case is written as 'default:' without the 'case' keyword. This causes a compilation error.

Multiple choice technology
  1. end

  2. compilation fails

  3. exception end

  4. exception test end

  5. A Throwable is thrown by main.

  6. An Exception is thrown by main.

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

The test method throws an AssertionError, which is a subclass of Throwable and Error, but not Exception. The catch block catches Exception, so the AssertionError bypasses it and propagates out of main, resulting in an uncaught Throwable thrown by main.