题一,如下代码的执行结果: class Person{ String name = "No name"; public Person(String nm){name = nm;} } class Employee extends Person{ String empID = "0000"; public Employee(String id){empID = id;} } class EmployeeTest{ public static void main(Str…
题目——如下代码的执行结果: class Hello{ String title; int value; public Hello(){ title += " World!"; } public Hello(int value){ this.value = value; title = "Hello"; Hello(); } } public class Test{ public static void main(String[] args){ Hello c =…
import static java.lang.System.*; class Base{ public String name; public double weight; public Base(String name,double weight){ this.name=name; this.weight=weight; } } public class getSuperConstructor extends Base{ public int age; public getSuperCons…
Super是指直接父类对象的引用,可以通过super来访问父类中被子类覆盖的方法和属性. 当你调用子类的构造方法时,系统会默认给你先调用父类的构造方法,然后才会调用子类的构造方法. package com.bjsxt.test; public class TestSuper02 { public static void main(String[] args) { System.out.println("开始创建一个ChildClass对象..."); new ChildClass();…
题目为如下代码的执行结果: class Building{} public class Barn extends Building{ public static void main(String[] args){ Building build1 = new Building(); Barn barn1 = new Barn(); Barn barn2 = (Barn)build1; Object obj1 = (Object)build1; String str1 = (String)build…
题目,如下代码的执行结果: import java.util.ArrayList; class Pizza{ ArrayList toppings; public final void addTopping(String topping){ toppings.add(topping); } public void removeTopping(String topping){ toppings.remove(topping); } } class PepperoniPizza extends Pi…