K
K
kate2019-03-03 14:17:37
Java
kate, 2019-03-03 14:17:37

How to work with classes?

Please help me, I am writing, in fact, the first program in Java.
I'm not very familiar with class methods yet. So the question is how to work with classes?
I have a program that sorts an array.
I roughly imagine that in main you need to insert the array itself, which needs to be sorted, and you also need to create 2 classes with 2 different sorts, how to do this?

class Sorting {
  
  public static void main(String[] args) {
    //ввожу здесь массив

    class Selection {

      //сортировка1

    }

    class Qsort {

      // сортировка2
    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2019-03-03
@sergey-gornostaev

What books to start learning Java?

M
Maksim Ivanov, 2019-03-05
@BlvckManeM

If in the Sorting class you want to use the logic implemented in Qsort & Selection then write:
Qsort qsort = new Qsort();
Selection selection = new Selection();
And then use it as you want, but of course it’s better to scatter each class into different files and switch between them in the future, thereby unloading the code and making it more readable.

B
Barrya42, 2019-03-04
@Barrya42

It is better, of course, to write an interface and implement it in each of these classes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question