0

これをコンパイルすると、ビデオに期待されるコンストラクター引数が「引数なし」であるというエラーメッセージが表示されます。

import java.util.*;

abstract class Thing
{

}

class Video extends Thing
{
    String description;
    int price;
    String title;

    void Video ( String d , int p, String t)
    {
        this.description = d;
        this.price = p;
        this.title = t;
    }

    String getDescription()
    {
        return description;
    }
}

class BookOnTape extends Thing
{
    String description;

    void BookOnTape ( String d )
    {
        description = d;
    }

    String getDescription()
    {
        return description;
    }
}

class Funiture extends Thing
{
   String description;

    void Furniture ( String d )
    {
        description = d;
    }

    String getDescription()
    {
        return description;
    }
}

public class Lookup
{
    /*private static HashMap<Thing, Integer> rentalList;

    static
    {
        rentalList = new HashMap<Thing, Integer>();
        rentalList.put( new Video(5), new Integer( 0 ) );
    }*/

    public static void main( String args[] )
    {
        System.out.println("fart");

        Thing farmer = new Video( "fgfg", 5, "gfgf" );
    }
}

これをコンパイルすると:

class A
{
}

class B extends A
{
    String name;

    B ( String n )
    {
        this.name = n;
    }
}


class TestPoly
{
    public static void main( String args[] )
    {
        A poly = new B( "test" );
    }
}

正常に動作します。違いはわかりません。ここに何か問題がありますか?...

4

2 に答える 2

4
void Video ( String d , int p, String t)

これはコンストラクターではありません。Video(String, int, String)コンパイラが文句を言うのはそのためです。コードにコンストラクタがないため、コンストラクタが見つかりません。メソッドには戻り値が必要ですが、コンストラクターには戻り値がないため、削除するvoidと1つになります。

(はるかに)より有益な議論はここにあります。

于 2013-03-07T22:53:20.047 に答える
0
void Video ( String d , int p, String t) is a method not a constructor. 

Constructor'svoidでさえないreturnタイプを持っていません。

さて、これはコンストラクターです:

 Video ( String d , int p, String t)
于 2013-03-07T22:53:29.823 に答える