Constructors

Question 1
Given a class named student, which of the following is a valid constructor declaration for the class?
A
Student student(){}
B
Private final student(){}
C
Student(student s){}
D
Void student(){}
       OOPS       Constructors       Nielit Scientist-B IT 4-12-2016
Question 1 Explanation: 
A constructor cannot specify any return type, not even void. A constructor cannot be final, static or abstract.
Question 2
Which two are valid constructors for Thread?
1. Thread(Runnable r, String name)
2. Thread()
3. Thread(int priority)
4.Thread(Runnable r, ThreadGroup g)
5.Thread(Runnable r, int priority)
A
1 and 3
B
2 and 4
C
1 and 2
D
2 and 5
       OOPS       Constructors       Nielit Scientific Assistance IT 15-10-2017
Question 2 Explanation: 
(1) and (2) are both valid constructors for Thread.
(3), (4), and (5) are not legal Thread constructors
Question 3
Which constructor will be called by the following lines of code?
(i) Student S1;
(ii) Student S2=S1;
A
First copy constructor, then default constructor
B
First default constructor, then copy constructor
C
Default constructor for both lines of code
D
Copy constructor for both lines of code
       OOPS       Constructors       KVS DEC-2013
Question 3 Explanation: 
→ Student S1:----whenever we create object to the class , automatically default constructor will be called.
→ Student S2=S1:------The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously.
Question 4
Implicit return type of a class constructor is:
A
not of class type itself
B
class type itself
C
a destructor of class type
D
a destructor not of class type
       OOPS       Constructors       UGC NET CS 2016 July- paper-3
Question 4 Explanation: 
Implicit return type of a class constructor is class type itself.

Syntax For Constructors:

Access_Modifier No Return_Type Class(...)

Example:

public static main(String [ ]args)

Constructor rules:

1. Constructors are always used with a new.

2. Have the same name as that of Class

3. Does not have a return type

4. Can be Overloaded but not Overridden.

There are 4 questions to complete.
PHP Code Snippets Powered By : XYZScripts.com