how to make a static reference in jave

Solutions on MaxInterview for how to make a static reference in jave by the best coders in the world

showing results for - "how to make a static reference in jave"
Diana
29 Feb 2017
1import java.util.Scanner;
2public class StudentMarks {
3   Scanner scan1 = new Scanner(System.in);
4   private double math;
5   private double science;
6   private double english;
7   public StudentMarks(double math, double science, double english) {
8      this.math = math;
9      this.science = science;
10      this.english = english;
11   }
12   public static boolean wasPromroted(StudentMarks marks) {
13      if(marks.math>=85 && marks.science>=75 && marks.english>=65)
14      return true;
15      return false;
16   }
17   public static void main(String args[]) {
18      Scanner sc = new Scanner(System.in);
19      System.out.println("Enter your math score: ");
20      double math = sc.nextDouble();
21      System.out.println("Enter your science score: ");
22      double science = sc.nextDouble();
23      System.out.println("Enter your english score: ");
24      double english = sc.nextDouble();
25      StudentMarks marks = new StudentMarks(math, science, english);
26      boolean bool = wasPromroted(marks);
27      if(bool) {
28         System.out.println("Congratulations you've got promoted");
29      } else {
30         System.out.println("Sorry try again");
31      }
32   }
33}
Alyssia
07 May 2019
1StudentMarks.java:16: error: non-static variable math cannot be referenced from a static context
2   if(math>=85 && science>=75 && english>=65)
3^
4StudentMarks.java:16: error: non-static variable science cannot be referenced from a static context
5   if(math>=85 && science>=75 && english>=65)
6^
7StudentMarks.java:16: error: non-static variable english cannot be referenced from a static context
8   if(math>=85 && science>=75 && english>=65)
9^
103 errors
Finn
01 Mar 2020
1import java.util.Scanner;
2public class StudentMarks {
3   Scanner scan1 = new Scanner(System.in);
4   private double math;
5   private double science;
6   private double english;
7   public StudentMarks(double math, double science, double english) {
8      this.math = math;
9      this.science = science;
10      this.english = english;
11   }
12   public static boolean wasPromroted(StudentMarks marks) {
13      if(math>=85 && science>=75 && english>=65) {
14         return true;
15      }
16      return false;
17   }
18   public static void main(String args[]) {
19      Scanner sc = new Scanner(System.in);
20      System.out.println("Enter your math score: ");
21      double math = sc.nextDouble();
22      System.out.println("Enter your science score: ");
23      double science = sc.nextDouble();
24      System.out.println("Enter your english score: ");
25      double english = sc.nextDouble();
26      StudentMarks marks = new StudentMarks(math, science, english);
27      boolean bool = wasPromroted(marks);
28      if(bool) {
29         System.out.println("Congratulations you've got promoted");
30      } else {
31         System.out.println("Sorry try again");
32      }
33   }
34}
queries leading to this page
cannot make a static reference to the non static method getnewslist 28 29 from the type newsrepositorymultiple markers at this line log cannot be resolved cannot make a static reference to the non static method info 28object 29 from the type logjava static referencein which circumstances should you use static reference to a non static methodcannot make a static reference to the non static method nextdouble 28 29 from the type randomcannot make a static reference to the non static field colorhow to make a refrence be non static javaannot make a static reference to the non static methodcannot make a static reference to the non static method fromjson 28string 2c class 3clong 5b 5d 3e 29 from the type gsonjava cannot make a static reference to a non static cannot make a static reference to the non static method seteditable 28boolean 29 from the type jtextcomponentwhat is a static reference in javahow to fix java static referencejava cannot make a static referencecannot make a static reference to the non static method appliesto 28 29 from the type recipientheaderparserjava 28603979977 29cannot make a static reference to the non static method containsword 28string 29 from the type forbidenwordshow to make a static reference to the non static method in javacannot make a static reference to the non static method getsubject 28string 29 from the type jwttokenprovidergetter cannot cannot make a static reference to the non static method getenemiesfixed 28 29 from the type enemiescannot make a static reference to the non static method circle 28float 2c float 2c float 29 from the type papplethow to make a static reference in jave cannot make a static reference to the non static method getxgetter cannot make a static referencecannot make static reference to non static methodcannot make a static reference to the non static methodcannot make a static reference to the non static method until 28function 29 from the type waitcannot make a static reference to the non static method tojson 28object 29 from the type gsonjava 28603979977 29java cannot make a static reference to a non static methodcannot make a static reference to the non static method playeradd 28player 2c string 29 from the type permissionstatic reference in javacannot make static reference to non static method javacannot make a static reference to the non static method add 28object 29 from the type listjava 28603979977 29how to make a refrence be static javacannot make public static floatcannot make a static reference to the non static method getbyid 28int 29 from the type productdaocannot make a static reference to the non static method save 28user 29 from the type crudrepository 3cuser 2clong 3e angularcannot make reference to non static fieldcannot make a static reference to the non static method add 28int 2c int 29 from the type javademohow to make a static reference in jave