weixin_46863753 2021-04-13 00:47 采纳率: 66.7%
浏览 48
已采纳

请问java中非静态方法怎么调用?

以下为参考书本以及一些帖子,写下的构建方法的程序。小白课程中刚学会构建方法并进行初始化,作业要求构建方法显示数据并使用该方法初始化。此前出错预览了一些帖子,修改过构建方法中的类型,但是一直出错,求大佬帮忙看看。

以下为版本1

//Object.java
//21/04/11
import javax.swing.JOptionPane;
//method to present the detail
class ObjectStore{
              String output;
              public void code(){
                  ouput = JOptionPane.showMessageDialog(null,"a bike with marked code is 19")
} 
              public void address(){
                  ouput + = "owned by the person who lives at 14 King Road"
} 
              public void district(){
                  ouput += "which is in police district 10"
} 
              public void show(){
                    JOptionPane.showMessageDialog(null,output, "The bike message" , JOptionPane.PLAIN_MESSAGE);
}
} 
//end the method to present the detail
}

public class Object{     
        public static void main(String arg[]){
               ObjectStore BikeInformation = new ObjectStore().show;

}
//end the main method
}
//end the class Object
                     
//Object.java
//21/04/11
import javax.swing.JOptionPane;
//method to present the detail
class ObjectStore{
               String Code;
              String Address;
               int District;

              public String setcode(String A){
                    this.Code = A;
	    return Code;
} 

              public  int setdistrict(int B){
                   this.District= B;
	   return District;
}

             public  String setaddress(String C){
                   this.Address= C;
	   return Address;
}                 
//end the method to present the detail
}
class TEST{ 
        public static void main(String arg[]){
               ObjectStore BikeInformation = new ObjectStore();
               ObjectStore.setcode("AXB");
               ObjectStore.setdistrict(19);
               ObjectStore.setaddress("14 Kings Road");
             JOptionPane.showMessageDialog(null,"a bike with marked code" +BikeInformation. Code + "owned by the person who lives at"
                                                                              + BikeInformation.Address + ",which is in police distric"
                                                                              + BikeInformation.District," The bike message ", JOptionPane.PLAIN_MESSAGE);
}
//end the main method
}
//end the class Object
                     

  • 写回答

3条回答 默认 最新

  • allway2 2021-04-13 06:16
    关注
    package Solutionmst1606;
    
    //Object.java
    //21/04/11
    import javax.swing.JOptionPane;
    
    //method to present the detail
    class ObjectStore {
    	String Code;
    	String Address;
    	int District;
    
    	public String setcode(String A) {
    		this.Code = A;
    		return Code;
    	}
    
    	public int setdistrict(int B) {
    		this.District = B;
    		return District;
    	}
    
    	public String setaddress(String C) {
    		this.Address = C;
    		return Address;
    	}
    //end the method to present the detail
    }
    
    class TEST {
    	public static void main(String arg[]) {
    		ObjectStore BikeInformation = new ObjectStore();
    		BikeInformation.setcode("AXB");
    		BikeInformation.setdistrict(19);
    		BikeInformation.setaddress("14 Kings Road");
    		JOptionPane.showMessageDialog(null,
    				"a bike with marked code" + BikeInformation.Code + "owned by the person who lives at"
    						+ BikeInformation.Address + ",which is in police distric" + BikeInformation.District,
    				" The bike message ", JOptionPane.PLAIN_MESSAGE);
    	}
    //end the main method
    }
    //end the class Object
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题