提交 e510b2f9 编写于 作者: CSDN-Ada助手's avatar CSDN-Ada助手

add type questions

上级 49cf2bb1
{
"type": "code_options",
"author": "clong",
"source": "Proxy.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Proxy
下列对http请求使用代理的方式正确的是:
## 答案
```
以上选择均正确
```
## 选项
### A
```java
// 在你发起Http请求之前设置代理属性
Properties prop = System.getProperties();
prop.setProperty("http.proxyHost", proxyHost);
prop.setProperty("http.proxyPort", proxyPort);
```
### B
```java
// 通过Proxy来配置代理信息
URL url = new URL("http://www.baidu.com");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
URLConnection conn = url.openConnection(proxy);
```
### C
```java
// httpclient设置代理
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.connectTimeout(Duration.ofSeconds(10))
.proxy(ProxySelector.of(new InetSocketAddress(proxyHost, proxyHost)))
.build();
```
......@@ -19,6 +19,6 @@
}
}
],
"export": [],
"export": ["Proxy.json"],
"title": "使用代理服务器"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Class.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Class
以下关于Class对象的说法错误的是:
## 答案
```
使用字面常量获取类对象会触发类的初始化
```
## 选项
### A
```java
可以通过Class.forName或者getClass获取类的Class对象
Class clazz = Class.forName("com.csdn.Test");
// 或者
Test test = new Test();
Class clazz = test.getClass();
```
### B
```java
可以通过字面常量的方式获取Class对象
Class clazz = Test.class;
```
### C
```
使用getClass和forName获取类对象都将会触发类的初始化
```
......@@ -27,6 +27,6 @@
}
}
],
"export": [],
"export": ["Class.json"],
"title": "Class对象"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Instanceof.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Instanceof
以下关于 `instanceof` 的说法错误的是:
## 答案
```
instanceof是类方法
```
## 选项
### A
```
instanceof用来判断一个对象是否是另一个类的实例
```
### B
```
判断的对象不能是基本类型
```
### C
```java
// instanceof伪代码描述为
boolean result;
if (obj == null) {
result = false;
} else {
try {
T temp = (T) obj;
result = true;
} catch (ClassCastException e) {
result = false;
}
}
```
{
"node_id": "java-48593d705752415e95c42b09d36bc2a4",
"keywords": [],
"keywords": ["instanceof"],
"children": [
{
"使用类字面常量": {
......@@ -27,6 +27,6 @@
}
}
],
"export": [],
"export": ["Instanceof.json"],
"title": "类型转换前先做检查"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Instanceof.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Instanceof
已知Person是Man的父类,以下结果为True的是:
## aop
### before
```java
Man man = new Man();
Person person = new Person();
```
## 答案
```
man instanceof Person
```
## 选项
### A
```java
man.getClass.equals(Person.class)
```
### B
```java
Man.class.isInstance(person)
```
### C
```java
person.getClass() == Man.class
```
......@@ -2,6 +2,6 @@
"node_id": "java-feca89c3fb9e4bcaba3f1f95e8ad4753",
"keywords": [],
"children": [],
"export": [],
"export": ["Instanceof.json"],
"title": "instanceof与Class的等价性"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "Reflect.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# Reflect
下列关于JAVA反射的说法正确的是:
## aop
### before
```java
```
## 答案
```
以上说法均正确
```
## 选项
### A
```
反射机制作用在程序运行状态
```
### B
```
能动态获取类的属性及方法并能进行调用
```
### C
```
反射首先要获取类的Class类对象
```
{
"type": "code_options",
"author": "clong",
"source": "ReflectTest.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# ReflectTest
以下程序是关于反射的一个例子,程序的控制台打印为:
```java
public class Reflect {
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Class clazz = Student.class;
Constructor con = clazz.getConstructor(String.class, Integer.class);
Student student1 = (Student) con.newInstance("小铭", 24);
Student student2 = new Student("小铭", 24);
System.out.println(student2 == student1);
System.out.println(student2.equals(student1));
}
}
```
## aop
### before
```java
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
class Student {
private String name;
private Integer age;
public Student() {}
public Student(String name, Integer age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
```
## 答案
```
false
false
```
## 选项
### A
```
false
true
```
### B
```
true
false
```
### C
```
true
true
```
{
"node_id": "java-42b26ca8a2384dcfb02fca6e159ace67",
"keywords": [],
"keywords": ["annotation"],
"children": [
{
"类方法抽取器": {
......@@ -127,6 +127,6 @@
}
}
],
"export": [],
"export": ["Reflect.json", "ReflectTest.json"],
"title": "反射:运行时类信息"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "DynamicProxy.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# DynamicProxy
下列关于JAVA动态代理的说法正确的是:
## 答案
```
以上说法均正确
```
## 选项
### A
```
为对象提供一个代理,控制对对象的访问
```
### B
```
动态代理有两种实现方式:JDK动态代理实现和CGlib字节码技术实现
```
### C
```
JDK动态代理只能代理接口而不能代理类
```
{
"type": "code_options",
"author": "clong",
"source": "DynamicProxyTest.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# DynamicProxyTest
以下程序是关于动态代理的一个例子,1和2处填入正确的是:
```java
interface Person {
void speak(String text);
}
public class DynamicProxyTest {
public static void main(String[] args) {
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
if (method.getName().equals("speak")) {
System.out.println("准备");
System.out.println(args[0]);
System.out.println("结束");
}
return null;
}
};
Person person = (Person) Proxy.newProxyInstance(
1,
2,
handler);
person.speak("你好,很高兴认识你。");
}
}
```
## 答案
```
Person.class.getClassLoader()
new Class[] { Person.class }
```
## 选项
### A
```
Person.getClassLoader()
Person.class
```
### B
```
Person.class.getClassLoader()
Person.getClass()
```
### C
```
Person.getClassLoader()
new Class[] { Person.class }
```
......@@ -2,6 +2,6 @@
"node_id": "java-f7be740717c442c4a489a8c8d675f38c",
"keywords": [],
"children": [],
"export": [],
"export": ["DynamicProxy.json", "DynamicProxyTest.json"],
"title": "动态代理"
}
\ No newline at end of file
{
"type": "code_options",
"author": "clong",
"source": "None.md",
"exercise_id": "",
"notebook_enable": true
}
\ No newline at end of file
# 空对象
下列关于空对象的说法错误的是:
## 答案
```
构造空对象是java内置的
```
## 选项
### A
```
空对象,没有赋值过,但是却在内存中存在
```
### B
```
空对象能避免报空指针异常
```
### C
```
有时候还是要判断对象是否为空对象
```
......@@ -11,6 +11,6 @@
}
}
],
"export": [],
"export": ["None.json"],
"title": "空对象"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册