Home > Software engineering >  Classes in Java- Main function
Classes in Java- Main function

Time:08-11

I'm a new student of Software development and my first homework its to find what was missing in a code. Searching, I found that the main funtion public static void main(String[] args) { its mandatory when classes are what we're talking about. But I'm getting errors and I don't know why. I could use some help right now. Also, if you know where I can find a course or web page where I can learn about Java, I would appreciate it a lot. I want to learn, but I don't know where to start, because the proffesor drop us classes without even knowing what's the difference betwen public and private.

I'm letting the code and the errors i got down here.

class Operaciones{

private int num1;
private int num2;
public static void main(String[] args) {


public int getNum1() {
   return num1;
}

public void setNum1(int num1) {
   this.num1 = num1;
}
public int getNum2() {
   return num2;
}
public void setNum2(int num2) {
   this.num2 = num2;
}

public int sumar (){
   return num1 num2;
}

public int restar (){
   return num1-num2;
}

public int multiplicar (){
   return num1*num2;

}
}
}

Errors

CodePudding user response:

You cannot declare other methods inside the main method. Also if you want to learn java you can follow this website https://www.w3schools.com/java/default.asp . I found it very useful and they explain java concepts very clearly. After you grasp the basic concepts of java try to develop mini projects [if have no idea try googeling for java mini projects] by yourself, it is the most efficient way to learn any programming language.

Some other java learning resources : https://www.geeksforgeeks.org/java/ https://www.tutorialspoint.com/java/index.htm

and you can try free video courses on udemy and youtube.

public class Operaciones{

    private int num1;
    private int num2;
    public static void main(String[] args) {

       //System.out.println("I am main class");
    
    }

    public int getNum1() {
      return num1;
    }

    public void setNum1(int num1) {
       this.num1 = num1;
    }
    public int getNum2() {
       return num2;
    }
    public void setNum2(int num2) {
       this.num2 = num2;
    }
    
    public int sumar (){
       return num1 num2;
    }
    
    public int restar (){
       return num1-num2;
    }
    
    public int multiplicar (){
       return num1*num2;
    
    }
    }
  • Related