Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么是超类型方法?_Java_Oop_Supertype - Fatal编程技术网

Java 什么是超类型方法?

Java 什么是超类型方法?,java,oop,supertype,Java,Oop,Supertype,我已经在谷歌上搜索了好几次,但仍然无法理解超类型方法。有人能解释一下这是什么吗?在OOPS中有一个超类型和子类型的概念,在java中,这种关系是通过继承实现的,即使用extends关键字: class A {} // super class class B extends A {} //sub class 在超类中声明的任何成员(字段、方法)都将被称为超类型 因此,在上面的上下文中,如果类A具有如下方法 class A { void set() } Set是类B的超类型方法 但是,请注

我已经在谷歌上搜索了好几次,但仍然无法理解超类型方法。有人能解释一下这是什么吗?

在OOPS中有一个超类型和子类型的概念,在java中,这种关系是通过继承实现的,即使用
extends
关键字:

class A {} // super class
class B extends A {} //sub class
在超类中声明的任何成员(字段、方法)都将被称为超类型

因此,在上面的上下文中,如果类
A
具有如下方法

class A {
   void set()
}
Set是类
B
的超类型方法

但是,请注意,如果有另一个类,请说
C

class C {
    void set()        
}

然后
set()
方法对于
C
类是非超类型的,因为类
A
和类
C
之间没有关系(关系由
extends
关键字创建,用于继承).

在java中,每件事都是对象,方法也是类java.lang.reflect.method的对象
因此,超级类型的方法可以被认为是超级代码类:代码> java .Lang.Eng.Fror < /Cord>这是<代码> Access Stabor < /C> > < /P> < P>如果你在谈论调用超级方法,你应该尝试以下的

  • 使用公共方法创建一个类,例如printSomething()

    公共空间{ System.out.println(“你好,我是头等舱”); }

  • 创建从第一个类继承的第二个类并重写printSomething方法

    @凌驾 公共空间{ super.printSomething(); }

  • 编写一个小程序,调用第二类的printSomething方法,看看会发生什么


  • 超类型和子类型是继承的属性,即为了代码的可重用性。我给你们举一个超级类和子类的例子。更多你可以跟随

    使用制度

    namespace MultilevelInheritance
    {
        public class Customer
        {
            public float fDis { get; set; }
            public Customer()
            {
                Console.WriteLine("I am a normal customer.");
            }
            public virtual void discount()
            {
                fDis = 0.3F;
                Console.WriteLine("Discount is :{0}", fDis);
            }
    
        }
        public class SilverCustomer : Customer
        {
            public SilverCustomer()
                : base()
            {
                Console.WriteLine("I am silver customer.");
            }
            public override void discount()
            {
                fDis = 0.4F;
                Console.WriteLine("Discount is :{0}", fDis);
            }
        }
        class GoldenCustomer : SilverCustomer
        {
            public GoldenCustomer()
            {
                Console.WriteLine("I am Golden customer.");
            }
            public override void discount()
            {
                fDis = 0.6F;
                Console.WriteLine("Discount is :{0}", fDis);
            }
    
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace MultilevelInheritance
    {
        class Program
        {
            static void Main(string[] args)
            {
                Customer objCus = new Customer();
                objCus.discount();
    
                SilverCustomer objSil = new SilverCustomer();
                objSil.discount();
    
                GoldenCustomer objGold = new GoldenCustomer();
                objGold.discount();
    
    
                Console.ReadLine();
            }
        }
    }
    

    Super用于调用父类属性 用于3个级别 变量构造函数和方法级别

    1.超级at变量

    class Super
    {
        int age;
        Super(int age)
        {
            this.age=age;
        }
            public void getAge()
            {
                System.out.println(age);
            }
    }
    class Sub extends Super
    {
        Sub(int age)
        {
            super(age);
        }
        public static void main(String[] args)
        {
             Super obj=new  Super(24);
             obj.getAge();
        }
    }
    

    施工人员级别的超级工程师

        class SuperClass
    {
        int num=10;
        public void display()
        {
            System.out.println("Superclass display method");
        }
    }
    class SubClass extends SuperClass
    {
        int num=20;
    
        public void display()
        {
            System.out.println("the value of subclass variable name:"+num);
            System.out.println("Subclass display method");
        }
            public void Mymethod()
            {
                super.display();
                System.out.println("the value of superclass variable name:"+super.num);
            }
            public static void main(String[] args)
            {
                SubClass obj=new SubClass();
                obj.Mymethod();
                obj.display();
            }
    }
    

    你的意思是超级类的方法如果我没有错的话,那就是使用
    super
    调用被另一个类扩展的类的方法,例如
    super。onCreate
    调用
    Activity类的
    onCreate
    方法。你能详细说明一下吗?你是否首先明确了面向对象编程?如果不是,我建议从这个开始。超类型在JAVA泛型中使用。此外,接口也是实现它的任何类(以及扩展它的任何接口)的超类型。这应该使界面默认方法也成为超类型方法。您好,您似乎在添加一个链接到一个没有公开从属关系的广告网站。看起来您正试图在站点上获取更多视图。看见请注意,这样做可能会增加社区成员的怀疑,从而导致您的帐户被暂停。参考这个。我写这篇评论是为了事先警告你。当做