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 |
Has anyone attended any interviews in IITs for the positions like Research Associates/Fellowships?
what is the difference between verification and validation
Hai friends this is Dara s. solanki, i done in B.Sc.(IT) i have an 2.3 years of exp in Manufacturing company in MIS giving support in SAP , 1 year back i did Sap course In MM Module. am trying from the day one to enter into the sap field but i was not.i kindly requesting all, please suggest me how to enter in to the SAP field. Looking for a job . i please help me and having any thing please let me know . i am in bangalore. my mail id is Dara.solanki@gmail.com. 8431455753
searching a B-tree indexed tree compared to B+ tree is slow..True or false
What is candidate key ? What is Alter net key ? & What is foreign key ?
What would be your first invention?
what is difference between class and object in c++
to print greatest of two integers without using >,<,=.
BEL old probationary engineering questions and answers
HI i have 2 year manual testing exp from MNC in pune but due to some reason i am looking job in testing . Friends hepl me to get the job i am not getting calls. alim24@gmail.com.09860643281
What is your Job Profile in IT feild.
Given a set of numbers like 1,2,5,4,1,2,1,7 find the number of faults using LRU.