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



if all user defined constructor of a class made private,can we create an object of that class?just..

Answer / mashruk

Yes, we can create an object of that class, but, we cannot
extend it.

Is This Answer Correct ?    3 Yes 1 No

if all user defined constructor of a class made private,can we create an object of that class?just..

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

Post New Answer

More Engineering AllOther Interview Questions

Has anyone attended any interviews in IITs for the positions like Research Associates/Fellowships?

0 Answers  


what is the difference between verification and validation

0 Answers   Sonata,


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

0 Answers   SAP Labs,


searching a B-tree indexed tree compared to B+ tree is slow..True or false

0 Answers   NIC,


What is candidate key ? What is Alter net key ? & What is foreign key ?

0 Answers   Globsyn,






What would be your first invention?

0 Answers  


what is difference between class and object in c++

0 Answers  


to print greatest of two integers without using >,<,=.

0 Answers  


BEL old probationary engineering questions and answers

0 Answers   BEL,


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

0 Answers  


What is your Job Profile in IT feild.

0 Answers  


Given a set of numbers like 1,2,5,4,1,2,1,7 find the number of faults using LRU.

1 Answers   NetApp,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4451)
  • Electrical Engineering Interview Questions Electrical Engineering (16632)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)