前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >每日一题(16)

每日一题(16)

作者头像
KEN DO EVERTHING
发布2019-01-17 16:15:32
2180
发布2019-01-17 16:15:32
举报
文章被收录于专栏:KEN DO EVERTHINGKEN DO EVERTHING

上题回顾与解析

public class Question15 {
    public static void main(String[] args){
        System.out.println("hello");
        http://hello.com;
        System.out.println(" world");
    }
}

这是一个有点诡异的问题。程序并没有做什么特殊的事情,而是直接打印hello world。这里其实使用了java中一个鲜为人知的特性「语句标号」,可在任意语句前防止语句标号,它只作提醒的作用。 一般都不使用标号,很容易会引起不必要的混淆与误解。如果确实需要使用标号,这样格式化更合理:

public class Question15 {
    public static void main(String[] args){
        System.out.println("hello");
        http: //hello.com;这里的//其实是注解的作用
        System.out.println(" world");
    }
}

每日一题

下面程序,输出什么?

public class Point {
    protected  int x,y;
    private  String name;

    Point(int x,int y){
        this.x = x;
        this.y = y;
        this.name = makeName();
    }

    protected  String makeName(){
        return "["+ x + "," + y +"]";
    }

    @Override
    public String toString(){
        return name;
    }

}

class ColorPoint extends Point{
     private String color;

     ColorPoint(int x, int y, String color){
         super(x,y);
         this.color = color;
     }

     @Override
     protected String makeName(){
         return super.makeName() + ":" + color;
     }

     public static void main(String[] args){
         System.out.println(new ColorPoint(4, 2, "blue"));
     }
}
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-11-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 java从心 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档