Multiple choice technology programming languages

What is a function in terms of Computer Science ?

  1. A group of code lines that performs a specific task

  2. A group of code lines that performs a whole program

  3. Something that contains an ‘init’

  4. The purpose of Java

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

A function is a modular, reusable block of code that performs a specific task. Option A correctly captures this definition. Option B is incorrect because a function typically performs a sub-task, not an entire program. Option C is too specific (not all functions have 'init'), and Option D is wrong because functions exist in all programming languages, not just Java.

AI explanation

In computer science, a function is a named, self-contained block of code that performs one specific task and can be invoked (often with parameters, optionally returning a value) from elsewhere in a program — this is the correct answer. It's wrong to say a function performs 'a whole program' because programs are typically composed of many functions working together, not one function equaling the whole program. 'Contains an init' is a red herring (init is a constructor/initializer concept, not the definition of a function), and 'the purpose of Java' is nonsensical since functions are a general programming concept, not language-specific.