Вы находитесь на странице: 1из 3

class and methods

Why is a class called a factory of objects? (2009)


Ans.
A class is known as a factory of objects because objects are instantiated from classes. Each
object gets a copy of the instance variables present in the class. It is like a factory producing
objects

2016 (c) Differentiate between formal parameter and actual parameter


ans
(c) Actual parameter : The parameter which is present in the function call statement is called
actual parameter. It stores the original value.
Formal parameter : The parameter which is present in function prototype or function
signature is called formal parameter. It stores the duplicate value.
2016 (d) Write a function prototype of the following :
A function PosChar which takes a string argument and a character argument and returns
an integer value.
ans
d) int PosChar( String s, char ch)

2016 (c) What is a parameterized constructor?


ans
(c) Constructors that take arguments are called parameterized constructors

2017 (b) What are the two ways of invoking functions?


ans
(b)
(i) Call by value OR Pass by value
(ii) Call by reference OR Pass by reference
2017 (c) Why is an object called an instance of a class?
ans
(c) An object is based on the blueprint as specified by the class or the copy of the class, every
object of a class reserves the memory of the same capacity of that of a class.

2017 (e) Differentiate between constructor and function


ans
(e) Constructor:
It is a function which is having same name as class name.
It has no return type, not even void data type.
It is invoked automatically as soon as the object of the class is created.
It has two types: default and parameterised.
It creates instance of class.
Function:
It is always defined by any name except keyword.
It has void or a valid return data type.
It must be called by using object of the class or directly.
It has two types: call by value and call by reference
It contains one or more executable statements
2017 (j) What is the difference between the Scanner class functions next() and nextLine()?
ans
(j) next() – accept a string without any space/Accepts a word / terminates the input of characters
when a space is met
nextLine() – accepts a string with the space / accepts a sentence .

2018 (d) How are private members of a class different from public members?
ans
(d) public members can be accessed from any other class.
private members can only be accessed within the declared class.

(d)
Write the prototype of a function check which takes an integer as an argument and
returns a character.
ans
d)
char check (int n)
2018 (d) Write two characteristics of a constructor.
ans
(d)
(i) Constructors have the same name as that of the class they belong to.
(ii) Constructors are executed when an object is created.
2018 (e) Write the output for the following:
System.out.println("Incredible"+"\n"+"world");
ans
(e)
Incredible
world
2019 (e) State a difference between call by value and call by reference
Call by value Call by reference
It works with primitive data type It works with reference data type
The original value of variable remains The original value of variable changes
unchanged
Operation is performed on duplicate value of Operation is performed on original values of
variables variables.
It is also called as pure function It is also called as Impure function.
2019 (j) What is meant by a package? Give an example.
ans
(j) Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces
Example: java.lang
java.util
java.io

Вам также может понравиться