Answer the question
In order to leave comments, you need to log in
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question