【问题标题】:Can someone help me with this example?有人可以帮我这个例子吗?
【发布时间】:2014-12-04 01:41:39
【问题描述】:

我刚开始在学校学习编程,但遇到了一个问题。 我知道这太容易了,但我没有得到任何这些。 我得到了创建类并构造到采用 int 数组类型的单个参数的类(我认为),但我没有得到方法部分。 另外,如果你们不想提供示例,请您至少给我明确的构造函数和方法定义,因为我无法理解它在java教程引用中所说的内容。

这是我目前的工作:

private int[] members;
    public Lesson3(int[] array1){
    this.members= array1;   
    }

这是我应该做的任务:

创建一个名为 GiveMeNext 的类。将构造函数添加到采用 int 数组类型的单个参数的类。将 int 数组存储在类的成员变量中。 向名为 getNextGreaterThan 的类添加一个成员方法,该方法有一个 int 参数并返回一个 int。

【问题讨论】:

标签: java arrays


【解决方案1】:

只是尝试帮助。如果我的回答有问题,请发表评论:)

public class GiveMeNext {

    // this is the member variable of the class marked as a private.
    // it is accessible only inside this class. 
    private int[] someArray;

    // this is your default Constructor.
    public GiveMeNext(){

    }

    // This is the constructor with a parameter.
    // Constructor  doesnt contain any return type 
    // You can create multiple Constructor in this class but ofcourse with diff parameter.
    public GiveMeNext(int[] someArray){
        this.someArray = someArray;
    }


    //this is the method getNextGreaterThan.
    // the 'int' after public is what we called return type.
    // the 'int someInt' is what we called parameter.
    // the return someInt is used to return the value of 'someInt'.
    public int getNextGreaterThan(int someInt){
        return someInt;
    }
}

有关更多信息,请查看这些参考/教程:

Constructor

Understanding Constructor

Method

Understanding Methods

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 2016-06-07
    • 2018-08-13
    • 2015-05-31
    相关资源
    最近更新 更多