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
IS THE SAMPLE POINT OF LPG SPHERE TANK PEFOR OR AFTER BUMP?
hey guys.... My name is Bandana Thakur.Im a cse(8th sem) student.i want to make my career in php language.i want to work with google,wipro,tcs,infosys.peoples tell me that the salary package of php developer is very less n these companies do not work in php language.please tell me what i do now? should i go with the php language or make my career in another language? pls reply me in my e-mail id bandana.thakur14at@gmail.com
I want old SBI question papers plzzzzzzzzz
nohup sort employees > list 2 > error out & what will happen?
what is c dot
Hi, I am preparing for Assistant Motor Vehicle Inspector (AMVI) exam.If any body having old question papers please send.My mail id is siyadndd@gmail.com
Which one is more efficient in terms of required memory space call-by-value or call-by-referance?
int i=~0; uint j=(uint)i; j++; printf(“%d”,j); what is the use of "uint" int the above code
can any give an exact example about, resolving the sql errorcode -305
describe how your code can determine if the user entered an input box value or click the cancel button?
What is meant by STL?
describe about storage allocation and scope of global,exterm,static,local and register variables in c language?
can i learn ad. java without learned core java? java is best or .net is best for summer training?
what is the heat insulation material is adaptable for a flue gas duct that carries waste heat from brick kiln to brick drier and what temperature is required to maintain at the tunnel to dry adobe bricks adequately
as a fresher what is the format for resume and suggest me some career objectives too........