if all user defined constructor of a class made private,can
we create an object of that class?justify your answer with
an example.
Answer Posted / 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 |
Post New Answer View All Answers
hey frnds..i have taken an emergency interview date of 21st july and my school is starting from 8th sept...i was continuously checking the date from 10 days but was not able to get a normal date...so can i get a rejection on this, that i have taken an emergency date.??????
HI i have 2 year manual testing exp from MNC in pune but due to some reason i am looking job in testing . Friends hepl me to get the job i am not getting calls. alim24@gmail.com.09860643281
What are the main assumptions that we make when we model potential flow?
What do you think determines a person's progress in a good company?
Explain the difference between RAM and ROM? What is “Volatile Memory
How EVA granules manufactured (I wanted to know the manufacturing process). (Virgin Granules) and what are the Raw Materials used.
how many clusters are generated by k-means algorithm?
What is the actual procedure of charging synthetic oil if the machine is under positive refrigerant pressure.
WHAT ARE THE ADVANTAGE OF SYSTEM ENGINEER
what are purchase order , sales order idoc names and idoc types
the controller valve fisher error: travel ??? not output input ok
in HVAC how does the chiller functioned .. and what is the chiller cyclic process
1. what is the opportunity in hardware & networking in future? 2.how many courses r in networking that fulfill market requrment? 3.who is better for career MCSE or CCNA ,UNIX ?
What is The Need of Template?
What is histogram? why and how it is used?