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
Answer / mashruk
Yes, we can create an object of that class, but, we cannot
extend it.
Is This Answer Correct ? | 3 Yes | 1 No |
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 |
why pegging is required for deaerator in power plant nd why maintain the constant pressure in deaerator 3.5 kg/cm2.
basic difference between run time and compile time polymorphism
What is the most important thing to know about marine engineering?
Paul the octopus who has been forecasting the outcome of FIFA world cup matches with tremendous accuracy has now been invited to predict ICC world cup matches in 2011. We will assume that the world cup contenders have been divided into 2 groups of 9 teams each. Each team in a group plays the other teams in the group. The top two teams from each group enter the semi finals ( after which the winner is decided by knockout). However, Paul has a soft spot for India and when India plays any team, Paul always backs India. Alas, his predictions on matches involving India are right only 2 out of 3 times. In order to qualify for the semi finals, it is sufficient for India to win 7 of its group matches. What is the probability that India will win the ICC world cup?
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
if we give you the job AS A PETROLEUM ENGINEER WHAT WILL YOU DO(that is extraordinary) for our company
what is LINUX?
What is necking in production engineering ?
what are basic step involved in embedded system software development?
what is routing protocals & routed protocals.
how to print a number in character(ex. 123= one twenty three)?
what is defect tracking in sotware testing