Function is a named code unlike method which is a part of an object
Function contained in an object is called a method
Function cannot change variables outside its scope unlike method
There is no difference between the two
Answer : (A)
A function is a piece of code that is called by name. It can be passed data to operate on and can optionally return data. All data that is passed to a function is explicitly passed.
A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:
Please login to submit your explanation
A function returns a value, but a procedure does not. A method is similar to a function, but is internal to part of a class. The term method is used almost exclusively in object-oriented programming. A function is something that takes a bunch of inputs and returns one or more values.
A function is a piece of code that is called by name. ... A method is a piece of code that is called by a name that is associated with an object.
You can check your performance of this question after Login/Signup
Consider the following code:
c= a*d+ b
integer a = 5, b = 20, c
integer d= 10
c = modify(a, b);
c = c+ d
then a=5 b=20 , c=?
Answer : (B)
Global variables are defined outside a function or any specific block, in most of the case, on the top of the C program. These variables hold their values all through the end of the program and are accessible within any of the functions defined in your program.
Any function can access variables defined within the global scope, i.e., its availability stays for the entire program after being declared.
Global variable is the answer because if you declare a variable globally then it can be used in any function
Protected and Private
Public and No Modifier
Only No Modifier
The function should be public so that it is not bound to any identifier.
Top-level classes can only have public, abstract, and final modifiers, and it is also possible to not define any class modifiers at all. This is called default/package accessibility. Besides that, private, protected, and static modifiers cannot be used when declaring top-level classes.
Since, getdata is private
getdata() is private so we cannot access through object. and name is a public variable of the class so, we can access using the object of that class
Answer : (B)
The statement 2 will generate an error as the function does not have any return type and it is returning 1 which will generate an error.
since the function is returning an integer after printing.
since function is returning integer after printing but the functionis string type
Function sum( n )
return (n + sum(n-1))
Anonymous Function is a function which has no name only the parenthesis
suppose, function _______ ( ) so here if ( ) is an anonymous function.
option is nowhere linked to the questions
if(n == 0 || n == 1)
— MISSING STATEMENT —
Answer : (D)
Let's Suppose n = 5
so it will compute the answer = 120;
int y = 10000;
int y = 34;
printf(“Hello World! %d\n”,y);
Compile time error
Hello World! 34
Hello World! 1000
Hello World! followed by a junk value
Compile time error will be raised, as the compiler will get confused which of the value is to be printed
compiler will say multiple declaration.
the compiler will say multiple declarations of y.
Please login to report
Buy TCS NQT Paid Materials
Join TCS NQT Online Classes
Personalized Analytics only Availble for Logged in users
Analytics below shows your performance in various Mocks on PrepInsta
Your average Analytics for this Quiz
Login/Signup to comment