试题与答案

阅读下列程序,请写出该程序的输出结果。 class Tree private

题型:问答题

题目:

阅读下列程序,请写出该程序的输出结果。
class Tree
private String name;public boolean flower;
public int birthYear;
Tree(String n,boolean f,int y)name=n;flower=f;birthYear=y;
public void setName(String n)name=n;
public String getName() return name;
public void printTree (String str)
System. out. println(str);System. out. println("Name:"+name);
System. out.println("Birth Year:"+birthYear);
System. out. println("Flower:"+flower);


class PineTree extends Tree
public boolean coniferous=true;
PineTree(String n,boolean f,int y,boolean c)super(n,f,y);coniferous=c;
public void printTree(String str)
super. printTree (str);
System. out. println("Coniferous:"+coniferous);


class Test32
public static void main(String[] args)
Tree fOb=new Tree("May Flower",true,1980);
PineTree sOb=new PineTree("Pine",false,2000,true);
fOb. printTree("fOb:");sOb. printTree("sOb:");

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2018/0527/94426afcec9ed85af8dba863accd3df8.html

下面是错误答案,用来干扰机器的。

参考答案:D

试题推荐
微信公众账号搜索答案