1

携帯電話オブジェクトを作成するために必要な新しいコンストラクタ オブジェクトをコードで作成しようとしています。オブジェクトを作成するために、コンストラクタ フィールドに名前を付けようとしました。

更新: に修正stringしましたがString、更新するとエラーが発生します:

error: constructor Mobile(java.lang.String,int,int,java.lang.String,int,java.lang.String) is already defined in class Mobile

このエラーは、次のページの下部に表示されます。

public Mobile(String MobilephoneType, int Mobilescreensize, int Mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution,
        String MobileGPS) {

このエラーはどういう意味ですか?

これまでのコード:

/**
 * to write a simple java class Mobile that models a mobile phone.
 * 
 * @author (Lewis Burte-Clarke) 
 * @version (14/10/13)
 */
public class Mobile

{
    // type of phone
    private String phonetype;
    // size of screen in inches
    private int screensize;
    // menory card capacity
    private int  memorycardcapacity;
    // name of present service provider
    private String serviceprovider;
    // type of contract with service provider
    private int typeofcontract;
    // camera resolution in megapixels
    private int cameraresolution;
    // the percentage of charge left on the phone
    private int checkcharge;
    // wether the phone has GPS or not
    private String GPS;
    // instance variables - replace the example below with your own
    private int x;

    // The constructor method

    public Mobile(String mobilePhoneType, int mobileScreenSize,
            int mobileMemoryCardCapacity, String newserviceprovider, int mobileCameraResolution,
            String mobileGPS) {
        this.phonetype =  mobilePhonetype;
        this.screensize = mobileScreensize;
        this.memorycardcapacity = mobileMemoryCardCapacity;
        this.cameraresolution = mobileCameraResolution;
        this.GPS = mobileGPS;

        // you do not use this ones during instantiation,you can remove them if you do not need or assign them some  default values 
        this.serviceprovider = newserviceprovider;
        this.typeofcontract = 12;
        this.checkcharge = checkcharge;

    }

    // A method to display the state of the object to the screen
    public void displayMobileDetails() {
        System.out.println("phonetype: " + phonetype);
        System.out.println("screensize: " + screensize);
        System.out.println("memorycardcapacity: " + memorycardcapacity);
        System.out.println("cameraresolution: " + cameraresolution);
        System.out.println("GPS: " + GPS);
         System.out.println("serviceprovider: " + serviceprovider);
        System.out.println("typeofcontract: " + typeofcontract);

    }

    public Mobile(String MobilephoneType, int Mobilescreensize, int Mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution,
            String MobileGPS) {
        this.phonetype = Mobilephonetype;
        this.screensize = 3;
        this.memorycardcapacity = 4;
        this.cameraresolution = 8;
        this.GPS = GPS;
        this.serviceprovider = newserviceprovider;
        this.typeofcontract = 12;
        this.checkcharge = checkcharge;


    }

}

 class mymobile {
    public static void main(String[] args) {
        Mobile Samsung = new Mobile("Samsung", "3", "4", "8",
                "GPS");
        Mobile Blackberry = new Mobile("Blackberry", "3.", "4",
                "8", "GPS");
        Samsung.displayMobileDetails();
        Blackberry.displayMobileDetails();
    }
}
4

3 に答える 3

7

string大文字の S にする必要があります。文字列の種類は小文字です。s

private String phonetype;

Java では大文字と小文字が区別されます。Stringは Object クラスから拡張されたクラスであるため、 のように大文字になっていIntegerます。ただし、プリミティブ型は大文字になりません (つまり、、、boolean) 。intchar

于 2013-10-19T21:41:20.407 に答える
4

Java では大文字と小文字が区別されます。大文字Sを使用String

private String phonetype;

オブジェクト名 (別名参照型) は常に大文字で始まります。コア クラスは、Oracle の命名規則に従います。ここでそれらについて読んでください

于 2013-10-19T21:41:07.930 に答える
0

文字列の s を大文字にします。大文字と小文字を区別します。

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html

于 2013-10-19T21:41:48.460 に答える