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
as a student of b.tech 2nd yr which is the best place for me to do my summer training and plz also tell me the complete procedure for the entrance?
What are special features of Silk Test ? In what way it is advanced than QTP?
1. Design a counter which counts 0, 4, 8, 2, 6, and repeats using: 1.a using JK flip flops 1.b using T flip flops 1.c using D flip flops 2. Modify your design in question 1.a so that the circuit works according to the following function table X Y F 0 0 Clear 0 1 No Change 1 0 Parallel Loading 1 1 Count 3. Design a circuit that detects the pattern 010 in a serial input X considering: 3.a Overlapping 3.b No overlapping
create a C program, the .exe file of that program run system will reboot any one help me
what are the various height of GSM mount and its base width ashim.port@gmail.com
Client server applications
A code which had some declarations of some data items. There were a couple of normal data items(char,int..) and some pointers as well and a malloc call. You have to find the total memory taken up in the stack(Hint:Pointers and all are allocated in heap, not in stack, so dont count them).Also in most of these questions, they were specifying that the OS was 32 bit
is the RKDF university is aicte approved for b.tech in computer
who is your role modal give in few sentances
How can I get know that my pc contains dram or sram..?
what is static identifier in c language?
hai iam selected in po exam in allahabad bank . my interview date is 02-06-2009. so plese send me some sample question on my email. my email is nitinbikhani@yahoo.com
Three pc now connected the 24 port switch.one pc ip adders 192.168.0.125,anather pc ip is 192.168.0.98, anather pc ip is 192.168.0.123, so 98 or 125 ping replay to 123,but 123 is not replay 125 or 98, but 123 is others pc ping replay,
What is the difference between operator overloading and function overloading in C when compared with C++?
how to increase the chiller effiency?