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
to acheve the IP 65 protection class does it is mandatory to apply silicon grease?
if a customer's blackberry stopped syncing their calendar wirelessly what would you do?if a customber deleted mail from his blackberry but it did delete from his mailbox how would ypu resolve this
Why is using C language
what are the simlerities between macro and subroutine
what is your weaknesses
please tell me difference between router and cisco router
my first question in huawei was ....1)Tell me about your self 2) oops concept 3)logic gates 4)ram and rom ,what is cache memory nd where it is located 5)diffrence between file system and data base 6) procedure of operating system 7)what is c# 8)high level language and machine language 9) and from mobile networkin !!!! hope thz will help you
Please. Does someone know how to inicialize tapes in ATL? I need have 100 tapes to init inside the ATL, how is the process to complete this request?
what is total power generation capacity in india at present (as on 12-12-2011)
what size shaft is required to transmit 100 hp @1000 RPM ,if max shear stress is 10,000 PSI,angle of twist must be less than 1' /ft/shaft is made of steel.
What is the difference between a .PST file and a .OST file?
what are the various login options used in loadrunner tool to make a application performance testing
what is the Relationship between quantity of Gas and capacity of AC machine in tonnage.
I have failed my intermediate can i write entrance exam the next year after completing my backlogs
which is the better form java or .net?exactly when we have to choose particcular 1 among them?