Return the bean

Report a typo

Write a program that contains this configuration class:

Java
@Configuration
public class Config {

    @Bean
    public String bean1() {
        return "String for bean1";
    }

    @Bean
    public String bean2() {
        return "String for bean2";
    }

    @Bean
    public int[] bean3() {
        return new int[]{1, 2};
    }
}
Kotlin
@Configuration
open class Config {
    @Bean
    open fun bean1(): String = "String for bean1"

    @Bean
    open fun bean2(): String = "String for bean2"

    @Bean
    open fun bean3(): IntArray {
        return intArrayOf(1, 2)
    }
}

An application context should be created based on that Config class:

Java
public class Application {
    public static void main(String[] args) {
        var context = new AnnotationConfigApplicationContext(Config.class);
    }
}
Kotlin
@SpringBootApplication
open class Application

fun main(args: Array<String>) {
    val context = AnnotationConfigApplicationContext(Config::class.java)
}

Match each getBean(...) method invocation with what it returns. You have the following options:

Java
A) context.getBean("bean1")
B) context.getBean("bean2", String.class)
C) context.getBean(String.class)
D) context.getBean(int[].class)
Kotlin
A) context.getBean("bean1")
B) context.getBean("bean2", String::class.java)
C) context.getBean(String::class.java)
D) context.getBean(IntArray::class.java)
Match the items from left and right columns
A
B
C
D
object of the String type
array of ints
throws an exception
object of the Object type
___

Create a free account to access the full topic