Question
public class CreatePro {
String ProductId;
public CreatePro(String ProductId) {
this.ProductId = ProductId;
}
public static Product creation_Product(String productId) {
System.out.println("Bean Created");
if ("aaa".equals(productId)) {
return new Battery("AAA", 2.5);
} else if ("cdrw".equals(productId)) {
return new Disc("CD-RW", 1.5);
}
}
}
<beans ...>
<bean id="aaa" class="CreatePro"
factory-method="createProduct">
<constructor-arg value="aaa" />
</bean>
<bean id="cdrw" class="CreatePro"
factory-method="createProduct">
<constructor-arg value="cdrw" />
</bean>
</beans>
a.
BeanCreationException
b.
Bean Created
c.
ClassPathException
d.
None of the mentioned
Posted under Java Spring Framework
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What will be the output?
Similar Questions
Discover Related MCQs
Q. A bean can have more than one name using multiple id attributes?
View solution
Q. Bean’s naming convention:-
starts with lowercase, camelcase from then on.?
View solution
Q. Beans can be created by which of the following properties?
View solution
Q. The bean instance is mentioned by the factory-method attribute, while the factory method is signified by the factory-bean attribute?
View solution
Q. One factory class can also hold more than one factory method.
View solution
Q. Instance Factory method main purpose is to encapsulate the object-creation process in a method of another object instance.
View solution
Q. Which Attribute is used to specify the bean declared?
View solution
Q. Declaring Beans using:-Ways to declare bean from a static field?
View solution
Q. Declaring Beans using:-Ways to declare bean from a static field?Declaring a bean from a static field requires a built-in factory bean FieldRetrievingFactoryBean and fully qualified field name or instance field is specified in the list property.As an alternative to specifying the field name in the staticField property explicitly, you can set it as the bean name of FieldRetrievingFactoryBean.
View solution
Q. Declaring Beans using:-
View solution
Q. Declaring Beans using:-Ways to declare bean from a static field?Declaring a bean from a static field requires a built-in factory bean FieldRetrievingFactoryBean and fully qualified field name or instance field is specified in the list property.
View solution
Q. Which tag is also allowed by static field?
View solution
Q. Declaring bean form object properties can be done using:-
View solution
Q. Inner Bean can be retrieved by it’s name.
View solution
Q. PropertyPathFactoryBean declares a bean from an:-
View solution
Q. The propertyPath property of PropertyPathFactoryBean can accept only a single property name.
View solution
Q. Alternate way of PropertyPathFactoryBean to declare a bean.
View solution
Q. We can combine target Object and propertyPath properties as bean name/id of PropertyPathFactoryBean.
View solution
Q. The Spring Expression Language can be accessed by:-
View solution
Q. A bean can be requested by:-
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Java Spring Framework? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!