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

please kindly send me the details about courses that are offered in nda

0 Answers  


how to send request to the direct server rather than proxy server

0 Answers  


3. Tell me about a time when you had too many things to do and you were required to prioritize your tasks.

0 Answers   Strad Energy,


what is the address bus length of an 8086 microprocessor?

1 Answers  


I am an Electrical engineering ( electrical back round ) ,can i get hvac Water system design details to easy understand ,i am working past 15years in Pharmaceuticals company with Engineering depart.

0 Answers   Archimedis Healthcare,






How can I boldly face the interview? Request:I am eagerly waiting for your replay.

0 Answers   Microsoft,


A rectangular sheet dimensions a x b is to be made into an open-topped box by cutting a square of side h from each corner and folding the 4 sides up. Find the value of h which allows the maximum volume of the box?

0 Answers  


A company canteen needs an automated system for its food and beverage management. The canteen receives food and beverage items from different distributors. All the non perishable items are stored in the store-room and the perishable items are put in the fridge. The manager should be able to add, delete or update food and beverage items onto the system and perishable and non perishable item details are to be stored separately. Both waiters and the cooks should be able to update the perishable items, but only the cooks should be allowed to update the non perishable items. Both cooks and waiters are not allowed to add or delete any items that are entered. identify the Schema, Table , Fields

0 Answers   Accenture,


Explain your experience in Lean Manufacturing and Six Sigma methods?

0 Answers  


hi , anyone plz end nic model papers to my id

0 Answers   NIC,


pls its urgent!!!!!!! can u tell me which companies are hiring fresher for industrail training???i know only two companies cmc which is in bandra n biz tech solution in kandivali. can anyone knows other companies??how much fees r they taking?? what about biz technology?this company is good to join if anyone has did d industrial training in biz technology then pls reply as urgent as possible. thank you ....waiting for replyyyyy

0 Answers  


what is difference between value datatype and object datattype

0 Answers  


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)