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");
      }
   }
}

3
2

                                    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(marks.math>=85 && marks.science>=75 && marks.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");
      }
   }
}

3 (2 Votes)
0
3.9
10
Brad C. 90 points

                                    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

3.9 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
static reference in java what is a static reference in java java cannot make a static reference to a non-static java cannot make a static reference to a non-static method java cannot make a static reference cannot make static reference to non-static method java java static reference how to make a static reference to the non-static method in java annot make a static reference to the non-static method Cannot make a static reference to the non-static method setEditable(boolean) from the type JTextComponent In which circumstances should you use static reference to a non static method getter cannot Cannot make a static reference to the non-static method getEnemiesFixed() from the type enemies getter cannot make a static reference Cannot make a static reference to the non-static method playerAdd(Player, String) from the type Permission Multiple markers at this line - log cannot be resolved - Cannot make a static reference to the non-static method info(Object) from the type Log Cannot make a static reference to the non-static method until(Function) from the type Wait how to fix java static reference Cannot make a static reference to the non-static method fromJson(String, Class<Long[]>) from the type Gson Cannot make a static reference to the non-static method appliesTo() from the type RecipientHeaderParserJava(603979977) Cannot make a static reference to the non-static method add(Object) from the type ListJava(603979977) Cannot make a static reference to the non-static method nextDouble() from the type Random Cannot make a static reference to the non-static method circle(float, float, float) from the type PApplet Cannot make a static reference to the non-static method getById(int) from the type ProductDao how to make a refrence be non-static java how to make a refrence be static java Cannot make a static reference to the non-static method add(int, int) from the type JavaDemo Cannot make a static reference to the non-static method save(User) from the type CrudRepository<User,Long> angular Cannot make a static reference to the non-static method getNewsList() from the type NewsRepository Cannot make a static reference to the non-static method getX cannot make static reference to non-static method cannot make a static reference to the non-static field color cannot make reference to non static field cannot make a static reference to the non-static method Cannot make a static reference to the non-static method containsWord(String) from the type ForbidenWords cannot make public static float Cannot make a static reference to the non-static method toJson(Object) from the type GsonJava(603979977) Cannot make a static reference to the non-static method getSubject(String) from the type JwtTokenProvider how to make a static reference in jave
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source