Answer to Question #152281 in Java | JSP | JSF for Hamza saeed

Question #152281
Consider the definition of the following class:
class CC
{
private int u;
private int v;
private double w;
public CC() //Line 1
{
}
public CC(int a) //Line 2
{
}
Ahmad sent 16 December at 09:42
public CC(int a, int b) //Line 3
{
}
public CC(int a, int b, double d) //Line 4
{
}
}
1
Expert's answer
2020-12-22T16:20:05-0500

1) CC one = new CC();

The call will go to Line 1

As here a object as been created with no parameters hence call will go to non-parameterized constructor

2) CC two = new CC(5,6)

The call will go to Line 3

Here the object is created with two parameters so the call will go to parameterized constructor with two arguments.

3) CC three = new CC(2,8,3.5)

The call will go to Line4

Here the object is created with three parameters now we have two constructor defined with three parameters one at line 4 and another at line5 but the call will go to line 4 because the passed arguments value matches with data type of parameters at line 4, i.e. int , int ,double ( here 2 is int , 8 is int and 3.5 is double).

4) The definition will as below

public CC()

{

u=0;

v=0;

w=0.0

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog