【问题标题】:Can we make object of subclass and call parent class method? [duplicate]我们可以制作子类的对象并调用父类的方法吗? [复制]
【发布时间】:2016-12-14 07:10:24
【问题描述】:
public class polymorphism {
    public void show()
    {
        System.out.println();
    }

    public void show(int i)
    {
        System.out.println("6");
    }

    public class B extends polymorphism 
    {

    } 

    /** * @param args the command line arguments */ 
    public static void main(String[] args) 
    { 
        // TODO code application logic here B obj=new B(); obj.show();
    }
}

【问题讨论】:

  • 特别是该重复问题的第二个答案就是您要寻找的。提示:类名在 Java 中以大写字母开头。总是。

标签: java


【解决方案1】:

要调用对象父类中的方法,可以使用“super”关键字。

例如。 super.show();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多