Cannot make a static reference to the non-static method playerAdd(Player, String) from the type Permission code example

Example 1: how to make a static reference in jave

StudentMarks.java:16: error: non-static variable math cannot be referenced from a static context
   if(math>=85 && science>=75 && english>=65)
^
StudentMarks.java:16: error: non-static variable science cannot be referenced from a static context
   if(math>=85 && science>=75 && english>=65)
^
StudentMarks.java:16: error: non-static variable english cannot be referenced from a static context
   if(math>=85 && science>=75 && english>=65)
^
3 errors

Example 2: how to make a static reference in jave

import java.util.Scanner;
public class StudentMarks {
   Scanner scan1 = new Scanner(System.in);
   private double math;
   private double science;
   private double english;
   public StudentMarks(double math, double science, double english) {
      this.math = math;
      this.science = science;
      this.english = english;
   }
   public static boolean wasPromroted(StudentMarks marks) {
      if(math>=85 && science>=75 && english>=65) {
         return true;
      }
      return false;
   }
   public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter your math score: ");
      double math = sc.nextDouble();
      System.out.println("Enter your science score: ");
      double science = sc.nextDouble();
      System.out.println("Enter your english score: ");
      double english = sc.nextDouble();
      StudentMarks marks = new StudentMarks(math, science, english);
      boolean bool = wasPromroted(marks);
      if(bool) {
         System.out.println("Congratulations you've got promoted");
      } else {
         System.out.println("Sorry try again");
      }
   }
}

Tags:

Java Example