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

what is the cycle between AHU and Chiller

0 Answers   RotoPower,


HOW CAN YOU RELATE THE FUNCTION WITH STRUCTURE EXPLAIN WITH APPROPRIATE EXAMPLES

0 Answers  


what is test initiation?can anybody post the answer urgently?

0 Answers  


the interviewer ask me If i accept to in lower position than the one i was tested for

2 Answers  


find the next number:60 24 7 4

1 Answers  


gsm features

0 Answers  


What are saw filters used for?

1 Answers  


What is the full forms SDDC,TOR,DLRO,PPP,USW,AWWA,CMOS,SVI,

1 Answers  


why this companay? For example: Why Dell?

1 Answers   DELL,


Differentiate y = sinx + cosx + tanx

0 Answers  


hi , anyone plz end nic model papers to my id

0 Answers   NIC,


how to count 4 column with two "and" condition in oracle? e.g task_type and cust_type and service_type are 3 column and we hv to count where task_type="new"and cust_type="jdp" and resulting column name will be new cust with jdp..and also we hv to count where task_type="new"and service_type="fs" resulting column name will be new cust with fs..

0 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4452)
  • Electrical Engineering Interview Questions Electrical Engineering (16637)
  • 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)