package home;
public class Home {
String HomeName = null;
int room = 0;
int kitchen = 0;
int bathroom =0;
//Constructor
Home(String HomeName){
System.out.println(HomeName);
}
Home(String HomeName, int rooms, int k ,int bathroom){
System.out.println(HomeName ":rooms:" rooms ":kitchen" k ":bathroom" bathroom);
this.HomeName = HomeName;
this.room = rooms;
this.kitchen = k;
this.bathroom = bathroom;
}
public void finaloutputhome(){
System.out.println("Your Home Name:" HomeName);
System.out.println("Rooms Count:" room);
System.out.println("kitchen Count:" kitchen);
System.out.println("Bathroom Count:" bathroom);
}
public static void main(String[] args) {
Home obj2 = new Home();
obj2.finaloutputhome();
}
}
錯誤代碼==>
*跑:
Exception in thread "main" java.lang.RuntimeException: Uncompilable code - no suitable constructor found for Home(no arguments)
constructor home.Home.Home(java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor home.Home.Home(java.lang.String,int,int,int) is not applicable
(actual and formal argument lists differ in length)
at home.Home.main(Home.java:1)
C:\Users\donra\AppData\Local\NetBeans\Cache\13\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\donra\AppData\Local\NetBeans\Cache\13\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 0 seconds)*
我需要的輸出===>>
Pasindu's Home:rooms:5:kitchen2:bathroom3
Your Home Name:null
Rooms Count:0
kitchen Count:0
Bathroom Count:0
uj5u.com熱心網友回復:
您應該在創建時傳遞引數Home:
new Home(null)
或者您應該添加一個不帶引數的建構式:
public Home() {
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/504515.html
下一篇:將長日期物件分組為月份物件
