if all user defined constructor of a class made private,can
we create an object of that class?justify your answer with
an example.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

i need to alone print a number no text by using if statement .say some idea

1626


how to initialize a pointer to an array?

1811


I am haning thousands emails in my send box (which i sended.) Now i want to send all these emails (Total in send box)to other by email. Can i send total emails at one time (Not sending each indivisually) by one comand; Please tell the steps..Thanks.

1788


Write a program to input 10 elements in an array and seperate even and odd numbers, positive and negative between them ?

1580


different types of protocols.......?

1669


What is the actual procedure of charging synthetic oil if the machine is under positive refrigerant pressure.

1478


What is the aim of Value Engineering?

950


1)How to calculate AC Capacity for the Room?

1998


what is advantages and disadvantages of vlan?

3997


Differentiate between data base and data mart?

1880


how you judge that your interview go good????

1725


why u r shifting from engineering to other field ?

1940


int main() { int d = 10; int m = 2; int y = 3603; int c = 0; int val; val = ( d + m + y + (y/4) + c) % 7; cout << val; return 0; }

1389


hi i am an CSE engg student and i cleared the PE exam of BEL 2012 both 24/07/012 and 01/08/2012 , so please if someone can help me with PE Interview question or subject or topics which i should cover that help me clear both Interview.PLZ help. my mail id is rjjkumar99@gmail.com

1864


I am having 5 nos. ceiling fans in my home. if i switch on all fan at full speed say 5 , so Will my meter reading be runing fast ? OR if I keep all fans on very low speed, say 1, so meter reading will runing slowly. or it does not make any difference whether low or high. reading will remain same?

1606