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 |
which is best car to buy in india, if the budget is below or equal to 3.5 lakhs?
what is the differences between DTD's and XML schema?
what is the difference between BE and BTECH??
describe about storage allocation and scope of global,exterm,static,local and register variables in c language?
URGENT.. I want to make a really good project using ADVANCE JAVA Can anyone suggest any great n innovative ideas I have nearly 4 months to make it so it can be big n time consuming... It should be Web Based also... It can use more than one Java Technologies.. Please suggest me something innovative n great.. thanks:
Explain a situation in which you handled a customer?s questions or problems?
Why is it that a single, all – encompassing metric cannot be developed for programme complexity or programme quality?
is it possible to get u.s visa with 55% in b-tech and 15 backlogs
what are macros?what are its advantages and disadvantages in c language?
how to store the vacuum in tank? its possible? what are the units for measure the vacuum ?
which is best car to buy in india, if the budget is below or equal to 3.5 lakhs?
THREE IS EQUAL TO FOUR
Civil Engineering (5086)
Mechanical Engineering (4453)
Electrical Engineering (16638)
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)