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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度