小编Flu*_*fle的帖子

调用超类的方法

该程序应该单独调用funFact每个子类,但它只调用该类中的funFact 方法Mammal.我究竟做错了什么?

 public class MammalFacts{
        public static class Mammal{
            public static String funFact(){
                return "If you are reading this, there's a 70% chance you're a mammal";
            }//end funFact

        }//end mammal
        public static class Primate extends Mammal{
            public static String funFact(){
                return "All primates can fly";
            }
        }//end Primate
        public static class Monkey extends Primate{
            public static String funFact(){
                return "Monkies will rule the earth someday";
            }
        }
        public static void main(String[]args){
            Mammal[]i = new Mammal[3]; …
Run Code Online (Sandbox Code Playgroud)

java subclass superclass

1
推荐指数
1
解决办法
50
查看次数

将字符串中的每个其他单词大写

我一直在尝试使用数组,但它似乎只是返回原始字符串.

public static String capitalizeEveryOtherWord(String x) {
    x = x.toLowerCase();
    x.trim();
    String[] words = x.split(" ");
    for(int c = 2; c < words.length; c += 2)
        words[c].toUpperCase();
    return Arrays.toString(words);
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

java

0
推荐指数
1
解决办法
709
查看次数

标签 统计

java ×2

subclass ×1

superclass ×1