Тесты
Язык сайта: Русский
Українська
English
Русский
Тесты по программированию
Вход
Регистрация
Тесты по программированию
Теория
сниппеты
Статьи
Главная
Android
Цены
FAQ
История Cosmo
Правила и условия сервиса
Политика конфиденциальности
Политика в отношении файлов cookie
Обратная Связь
reflection
:
Язык контента: English
Русский
What will be the output of the following code? package question; import java.lang.reflect.Method; class Test { public void methodPublic() { System.out.println("Test.methodPublic"); } protected void methodProtected() { System.out.println("Test.methodProtected"); } private void methodPrivate() { System.out.println("Test.methodPrivate"); } } public class PrivateTest { public static void main(String[] args) throws Exception { Test test = new Test(); callMethods(test, "methodPublic"); callMethods(test, "methodProtected"); callMethods(test, "methodPrivate"); } static void callMethods(Object a, String methodName) throws Exception { Method m = a.getClass().getDeclaredMethod(methodName); m.setAccessible(true); m.invoke(a); } }
reflection
What will be the result of compilation and execution of the following code? public class Test<T>{ static class MyTest{ public MyTest(int k) { System.out.println("MyTest created"); } } T obj1, obj2; public Test(T t, Class<T> cls) throws Exception { obj1 = t; // 1 obj2 = cls.newInstance(); // 2 } public static void main(String[] args) throws Exception { MyTest mt = new MyTest(10); Test t = new Test(mt, MyTest.class); } }
reflection
← Предыдущая
1
Следующая →
Зарегистрируйся сейчас
или
Подпишись на будущие тесты