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

how to generate linked implementation of sparse matrix?

0 Answers  


DIRECTIONS for questions 8 and 9: Refer to the data below and answer the questions that follow. There are seven chapters in a mathematics book - A, B, C, D, E, F, and G. The instructor has to follow certain rules while teaching them. i. E cannot be taught before B and C. ii. D should be taught before C and G. iii. B cannot be taught before G. iv. F cannot be taught before C, D, and G. v. A should be taught before B is taught and the two should not be taught consecutively. Q8. If only four chapters are taught, which of the following has to be necessarily false? a) The instructor can get away without teaching F. b) The instructor can avoid teaching E. c) The instructor can avoid teaching C. d) The instructor can avoid teaching G. Q9. If only four chapters are to be taught, which of the following is necessarily true? a) A has to be taught. b) D has to be taught. c) B has to be taught. d) C has to be taught. Q8. If only four chapters are taught, which of the following has to be necessarily false? a) The instructor can get away without teaching F. b) The instructor can avoid teaching E. c) The instructor can avoid teaching C. d) The instructor can avoid teaching G. Q9. If only four chapters are to be taught, which of the following is necessarily true? a) A has to be taught. b) D has to be taught. c) B has to be taught. d) C has to be taught.

1 Answers   Crisil,


1. Describe a time when you anticipated potential problems and developed Preventive measures.

0 Answers   Strad Energy,


b. how the type of transmission medium can affect the performance of a network

2 Answers  


If a stored procedure is taking a table data type, how it looks?

0 Answers  






write a c program which accept input as:Anu.B.Kapur and give out as:Kapur.A.B using pointers

0 Answers   Boredbees,


how is the config take place and from reciever side how will process the data into internal table

0 Answers  


what is advantages and disadvantages of vlan?

0 Answers  


I attended an interview with CGI last week for network engineer and here are the questions that might help you guys who are going to attend interviews.

1 Answers   CGI,


In HSE what is Lost time accident? why it is to be reported within 48 hrs to gov.authorities ?

0 Answers  


hi........ i am a student of computer science. i want to earn some money on net so that i can help my parents. so please suggest me some sites which give online part time jobs without any registration charges. please help me. i will be very thankful to you. varinder.

1 Answers  


sir ,,kindly provide me 10 year old solved question papers of gate ,i am from CS. branch...

0 Answers  


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