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 |
PLC Training in chennai ? Best PLC Training center in chennai?
Including stoppage speed of a bus is 54km/hr while excluding stoppage of bus is 45km/hr.Find the time that the bus has been spread on stoppage?
multithreading??
what is instance in oops?
what is dns?
Hi i'm richa piplani applied for ATC(IT) if u have the syllabus & old question papers forward me.I will be very much thankful to you. piplani.richa@gmail.com and sonu_pips@yahoo.co.in
Q1. A. Compare the advantages and disadvantages of a three- dimensional monitor using a varifocal mirror with a stereoscopic system. B. Write a routine to implement the polymarker function.
4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it. I did the following program and is this correct
What are the input documents to 1.Functional testing,2.System testing and 3.Integration testing. Whether there will be separate test cases for regression testing or functional testing?
is java supprot the complier time pollymorphism or run time pollymorphism ... why
Why do you want to work here
376,188,88,40,16,4,-2. Find wrong term in series
Civil Engineering (5086)
Mechanical Engineering (4456)
Electrical Engineering (16639)
Electronics Communications (3918)
Chemical Engineering (1095)
Aeronautical Engineering (239)
Bio Engineering (96)
Metallurgy (361)
Industrial Engineering (259)
Instrumentation (3014)
Automobile Engineering (332)
Mechatronics Engineering (97)
Marine Engineering (124)
Power Plant Engineering (172)
Textile Engineering (575)
Production Engineering (25)
Satellite Systems Engineering (106)
Engineering AllOther (1379)