What is a function in terms of Computer Science ?
-
A group of code lines that performs a specific task
-
A group of code lines that performs a whole program
-
Something that contains an ‘init’
-
The purpose of Java
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.
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.