P
P
pshy_soch2020-06-08 21:12:58
Java
pshy_soch, 2020-06-08 21:12:58

Main method not found in java?

package com.company;


public class QDemo2 {
    static double rootof2;
    static double rootof3;

    static {
        System.out.println("Внутри синтаксического блока QDemo2!");
        rootof2 = Math.sqrt(2.0);
        rootof3 = Math.sqrt(3.0);
    }

    QDemo2(String msg) {
        System.out.println(msg);
    }
}

    class SDemo3{
        public static  void main(String[] args){
            QDemo2 ob = new QDemo2("Внутри конструктора !");
            System.out.println("Корень квадратныйй из 2 равен" + QDemo2.rootof2);
            System.out.println("Корень из 3 " + QDemo2.rootof3);
        }
    }

As you can see, the Main method exists.
So what's the problem?
sw2bda

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Cheremisin, 2020-06-08
@pshy_soch

Make the SDemo3 class public!

O
Orkhan, 2020-06-08
Hasanly @azerphoenix

There can be several classes in one java file, but one of them must be public. The class in which the static public method main is called must be public

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question