黑马程序员_JAVA基础联系题
来源:互联网 发布:windows bat date 编辑:程序博客网 时间:2024/06/07 12:21
------- android培训、java培训、期待与您交流! ----------
1.
public class Joker {
public static void func() {
try {
throw new Exception();
}
finally {
System.out.println("B");
}
}
public static void main(String[] args) {
try {
func();
System.out.println("A");
}catch (Exception e) {
// TODO: handle exception
System.out.println("C");
}
System.out.println("D");
}
}
//编译失败。因为func抛出了异常而函数上没有申明。
如果func()上抛出了Exception 结果会是BCD。
2.public class Joker extends Test{
Joker() {
super();
System.out.println("Joker");
}
public static void main(String[] args) {
new Joker();
new Test();
}
}
class Test {
Test() {
System.out.println("Test");
}
}
结果是Test,Joker,Test(这题考察的是子类的实例化过程)
3.public class Joker{
public static void main(String[] args) {
A a = new B();
System.out.println(a.func());
}
}
interface A{}
class B implements A {
public String func() {
return "func";
}
}
结果是:编译失败。父类中并没有定义func()方法。
4.
public class Joker extends Fu{
public static void main(String[] args) {
int i = 0;
Fu f = new Joker();
Joker j = new Joker();
for(f.show('A');f.show('B')&&(i < 2);f.show('C')) {
i++;
j.show('D');
}
}
boolean show(char a) {
System.out.println(a);
return false;
}
}
class Fu {
boolean show(char a) {
System.out.println(a);
return true;
}
}
结果为:A.B因为在for里面第一次判断show()的时候由于子类重写了了父类的方法返回false了。所以退出了for循环。
5.
public class Joker extends Fu{
public static void main(String[] args) {
A a = get();
System.out.print(a.test());
}
static A get() {
return new B();
}
}
interface A {}
class B implements A {
public String test() {
return "yes";
}
}//编译失败。
6.
public class Joker extends Super{
public static void main(String[] args) {
int i = 4;
Super d = new Joker("A");
System.out.println(d.i);
}
public Joker(String a) {
System.out.println("C");
i = 5;
}
}
class Super {
int i = 0;
public Super(String a) {
System.out.println("A");
i = 1;
}
public Super() {
System.out.println("B");
i+=2;
}
}//结果为B C 5当S执行uper d = new Joker("A");的时候会读Joker父类的构造函数Super();
7.public class Joker{
public static void main(String[] args) {
//补足代码;调用两个函数,要求用匿名内部类.
}
}
interface Inter {
void show(int a ,int b);
void func();
}
答案:
public class Joker{
public static void main(String[] args) {
//补足代码;调用两个函数,要求用匿名内部类.
Inter ii = new Inter() {
public void show(int a,int b) {
}
public void func() {
}
};
ii.show(0, 0);
ii.func();
}
}
interface Inter {
void show(int a ,int b);
void func();
}
8.
public class Joker{
public static String output="";
public static void foo(int i) {
try {
if(i == 1) {
throw new Exception();
}
output += "1";
}catch (Exception e) {
// TODO: handle exception
output += "2";
return;
}finally {
output+="3";
}
output+="4";
}
public static void main(String args[]) {
foo(0);
System.out.println(output);
foo(1);
System.out.println(output);
}
}//结果为123 13423
- 黑马程序员_JAVA基础联系题
- 黑马程序员_java基础
- 黑马程序员_java基础
- 黑马程序员_java 基础
- 黑马程序员_java基础
- 黑马程序员_Java基础
- 黑马程序员_java基础
- 黑马程序员_java基础
- 黑马程序员_java基础
- 黑马程序员_Java基础
- 黑马程序员_java基础
- 黑马程序员_java基础
- 黑马程序员_java基础
- 黑马程序员_Java基础
- 黑马程序员_java基础
- 黑马程序员_Java基础
- 黑马程序员_java基础
- 黑马程序员_java基础
- 对一组数穷尽所有排列的算法
- 【JAX-WS入门系列】第05章_契约优先开发及隐式声明头信息
- hdu 1856 并差集
- insert /*+append*/和各种insert插入速度比较
- Intellij idea中编辑器中光标太长的解决办法
- 黑马程序员_JAVA基础联系题
- sharepoint 无法显示此视图,由于其包含的查阅和工作流状态栏数超出了管理员强制实施的阀值
- hdu 1907 博弈
- Lana Del Rey
- opencv 开源图像拼接
- 来自越南的离线binx刷机工具
- hdu 2159 二维费用背包
- Hello Win32 之疯狂注释版
- 黑马程序员__关于学习Java基础加强的总结_2