| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5234 人关注过本帖
标题:构造方法也需要返回值类型吗? ******谢! 写了那么的方法是否有点重复, ...
取消只看楼主 加入收藏
yinmingzheng13
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-4-13
结帖率:100%
收藏
 问题点数:0 回复次数:2 
构造方法也需要返回值类型吗? ******谢! 写了那么的方法是否有点重复,能否就重要的几种详细说明
class Person
{
    String name;
    int age;
    
    
    static int x;
    
    Person( String n,int a)
    {
        name = n;
        age = a;
    }
    
    Person( String n)
    {
        name = n;
        age =-1;
    }
    
    Person( int age,String name)
    {
        this.age = age;
        this.name = name;
    }
    
    Person()
    {
        this(0,"");
    }
    
    void sayHello()
    {
        System.out.println("Hello!My name is"+ name);
    }
    
    void sayHello( Person another)
    {
        System.out.println("Hello,"+another.name+"!My name is "+name);
    }
    
    boolean isOlderThan( int anAge)
    {
        bloolean flg;
        if( age> anAge ) flg=true; else flg=false;
        return flg;
    }
    
    
    public static void main (String[] args)
    {
        System.out.println("Hello World!");
        
    }
    
    class Student extends Person
    {
        String school;
        int score;
        //void sayHello(){
            //System.out.println("Hello! My name is "+ name+ ".My school is"+ school);//}
    }
    
    void sayHello( Student another)
    {
        System.out.println("Hi");
        if(school==another.school) System.out.println("Schoolmate");
    }
    
    boolean isGoodStudent()
    {
        return score>=90;
    }
    void testThisSuper()
    {
        a = age;
        a = this.age;
        a = super.age;
    }
   
    void sayHello()
    {
        super.sayHello();
        System.out.println("My school is" +school);
    }
   
   
    Student(String name,int age,String school)
    {
        super(name, age);
        this.school = school;
    }
   
    Student(){}
   
    public void main( String [] args)
    {
        Person p = new Person("Liming",50);
        Student s =  new Student("Wangqiang",20,"PKU");
        Person p2 = new Student("Zhangyi",18,"THU");
        Student s2 = (Student) p2;
    }
}
搜索更多相关主题的帖子: 返回值 详细说明 类型 构造 
2008-04-14 20:09
yinmingzheng13
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-4-13
收藏
得分:0 
编译时描述说:   
         ....................................
         ....................................
         ....................................
         void sayHello()
    {
        super.sayHello();
        System.out.println("My school is" +school);
    }
   
   
    Student(String name,int age,String school)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    {
        super(name, age);
        this.school = school;
    }
   
    Student(){}
    ~~~~~~~~~~~
    public void main( String [] args)
    {
        Person p = new Person("Liming",50);
        Student s =  new Student("Wangqiang",20,"PKU");
        Person p2 = new Student("Zhangyi",18,"THU");
        Student s2 = (Student) p2;
    }
}
                打波浪线的两句:  方法生命无效;需要返回值类型

无师自通
2008-04-16 13:27
yinmingzheng13
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-4-13
收藏
得分:0 
    上面的大哥 你在哪地方做了修改?

无师自通
2008-04-20 19:45
快速回复:构造方法也需要返回值类型吗? ******谢! 写了那么的方法是否有点重 ...
数据加载中...
 
   



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

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