if all user defined constructor of a class made private,can
we create an object of that class?justify your answer with
an example.
Answers were Sorted based on User's Feedback
Answer / mashruk
Yes, we can create an object of that class, but, we cannot
extend it.
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / sp
Object can be created only within the same class but not in
another class (including sub class)
Eg:
// valid instantiation
public class ClassWithPrivateConstructors {
private ClassWithPrivateConstructors() {
System.out.println("object created");
}
public static void main(String args[]) {
ClassWithPrivateConstructors t = new
ClassWithPrivateConstructors();
}
}
//invalid instantiation - subclass
public class SubClassWithPrivateConstructors extends
ClassWithPrivateConstructors {
public NewClassConstructorTest(String name) {
//implicitly super() constructor in super
class is invoked.
System.out.println("New sub class object created" + name);
}
}
//invalid instantiation - reference class
public class ClassWithPrivateConstructorsTest {
public ClassWithPrivateConstructorsTest() {
ClassWithPrivateConstructors c = new
ClassWithPrivateConstructors();
}
}
Is This Answer Correct ? | 2 Yes | 0 No |
what is the cycle between AHU and Chiller
HOW CAN YOU RELATE THE FUNCTION WITH STRUCTURE EXPLAIN WITH APPROPRIATE EXAMPLES
what is test initiation?can anybody post the answer urgently?
the interviewer ask me If i accept to in lower position than the one i was tested for
find the next number:60 24 7 4
gsm features
What are saw filters used for?
What is the full forms SDDC,TOR,DLRO,PPP,USW,AWWA,CMOS,SVI,
why this companay? For example: Why Dell?
Differentiate y = sinx + cosx + tanx
hi , anyone plz end nic model papers to my id
how to count 4 column with two "and" condition in oracle? e.g task_type and cust_type and service_type are 3 column and we hv to count where task_type="new"and cust_type="jdp" and resulting column name will be new cust with jdp..and also we hv to count where task_type="new"and service_type="fs" resulting column name will be new cust with fs..