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
How we can read an Image in VC++?How we can find out the intensities of the pixels of an image and dimension of the image?
what is locative information on web.........?
#include
PLEASE SUGGEST THE BALLY PLACEMENT PAPER PATTERN ABOUT WRITTEN TEST,INTERVIEW,HR.ITS URGENT. AS BALLY IS GOING TO VISIT OUR CAMPUS.
what are the artifacts in coding phase in SDLC????
can oracle driver be directly connected with odbc driver??
how to send request to the direct server rather than proxy server
WHAT HAPPEN WHEN ANY SPINDLE RUN OVER 10 MM HEIGHT ABOVE BOLSTAR IN RING SPINNING FRAME
Derive the equation that links voltage, charge and capacitance.
I am helping a friend to design a concert hall. No need for super architectural show off. Just a rectangular box. Knowing that in my country constructions are done with reinforced concrete and concrete blocks and that the hall's dimensions are, length: 75 meters, width: 32m height: 9m, and that there should not be any columns inside, what would be the size of the columns, beams and roof slab ?
minimum percentage in B.E in(INFORMATION TECHNOLOGY) to be eligible for IES exam qualification and also for reserved categories.are IT engineers are eligible for giving IES exams? please reply soon.
i m doing engg in IT .for getting job which courses i have to do?
WHY IBM MAINFRAME TECHNOLOY IS USED.THOUGH, SINCE ITS INTRODUCTION IT HAS NO MAJOR UPDATATION OR MODIFICATION;BUT STILL IT IS IN DEMAND........WWWWWWWWWWWWWWHHHHHYYYYYYYY????????????
please send aptitude test papers for reference with answers
Problem:Design and implement a class that allows a teacher to track the grades in a single ourse.Include methods that calculate the average grae, the highest grade, and the lowest grade.Wrute a program to testyour class implementation in a c#. given grades:integral=85, physics=87, datastruct=84.