1. python 和java的区别

2022/9/17 1:17:11

本文主要是介绍1. python 和java的区别,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、python 和java 继承的区别

class Person():
    def __init__():
      print("person")
		
class Student():
    def __init__():
      print("Student")
		 
a=Student():
# 当实例化Student这个类的时候, 会首先调用自己的init 方法,当自己没有init方法是才会调用父类的init 方法
package com.makuo.day3;

public class Exercise2 {

    public static void main(String[] args) {


        Exercise3 e3=new Exercise3();
	//Exercise5和Exercise3都有自己的构造器,Exercise3 继承Exercise5 ,那么 Exercise5的Exercise3的构造器都会被调用

    }
}

class  Exercise3 extends Exercise5{

    public Exercise3(){
//        super();    //super()方法会自动添加
        System.out.println("Exercise3");
    }
}

class Exercise5 {

    public Exercise5() {
        System.out.println("Exercise5");
    }
}

python的子类如果自己有初始化方法不会使用父类的,java无论如何都会调用父类的构造器



这篇关于1. python 和java的区别的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程