| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 431 人关注过本帖
标题:请高手回答 填空题
只看楼主 加入收藏
yesfengfeng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-6-22
收藏
 问题点数:0 回复次数:0 
请高手回答 填空题
class Cat
{
    int age;
    int weight;
    void meow()
    {
        System.out.println("Meow.......");
    }
}
class Dog
{
    int age;
    int weight;
    Dog()
    {
        age=2;
        weight=4;
    }
    Dog(int a,int w)
    {
        age=a;
        weight=w;
    }

    void wang()
    {
        System.out.println("wang.......");
    }
}
class Num
{
    int i;——————
}
public  class Test
{
    public static void main(String []args)
    {
        Cat cat1=new Cat();
Cat cat2=new Cat();
Dog dog1=new Dog();
Dog dog2=new Dog(3,5);
Num num1=new Num();
Num num2=new Num();
num1.i=1;num2.i=2;
System.out.println("num1.i="+num1.i+"     num2.i="+num2.i);

            ____________________ ______________                     
        num2=num1;
        num2.i=9;
        System.out.println("num1.i="+num1.i+"     num2.i="+num2.i);

                _____________________  ______________________                 
        System.out.println("cat1.age="+cat1.age+"     cat2.age="+cat2.age);

                     _______________________ ______________            

        System.out.println("cat1.weight="+cat1.weight+"     cat2.weight="+cat2.weight);

               __________________     _____________                  

        System.out.print("cat1.meow:");
        cat1.meow();
        System.out.print("cat2.meow:");
        cat2.meow();
        
        System.out.println("dog1.age="+dog1.age+"     dog2.age="+dog2.age);

                     ________________ ________________            

        System.out.println("dog1.weight="+dog1.weight+"     dog2.weight="+dog2.weight);

        _________________ ___________________                        

        System.out.print("dog1.wang :");
        dog1.wang();

        __________________     

        System.out.print("dog2.wang :");
        dog2.wang();

            
_____________________
        
    }
}

class Animal
{
    public void speak()
    {
        System.out.println("Animal speak...");
    }
 }

class Dog extends Animal
{
    public void speak()            
    {
        System.out.println("Bowwow...");
    }
}

class Cat extends Animal
{
    public void speak()
    {
        System.out.println("Meow...");
    }
}

public class TestPolymorphism
{
    public static void makeSpeak(Animal a)
    {
        a.speak();
    }
    public static void main(String[] args)
    {
        Cat c=new Cat();
        Dog d=new Dog();
        makeSpeak(c);
_______________________
                  
        makeSpeak(d);   

      _____________            
    }
}
搜索更多相关主题的帖子: 填空题 
2011-06-22 10:37
快速回复:请高手回答 填空题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.067232 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved