报错原文:Cannot make a static reference to the non-static method maxArea(Shape[]) from the type ShapeTestb

报错原因:在一个类中写了一个public void maxArea ()方法和一个main()方法,在main()方法中直接调用maxArea()方法就出现如题的错误。

解决方法,有两种:

方法一、maArea()定义时加上修饰符static,即变为public static void maxArea(),即可在main()方法中正确调用。

public class ShapeTestb {
public static void main(String[] args) {
Shape[]shapes = new Shape[2];
maxArea(shapes);
}
//在main()中编译错误
//public void maxArea(Shape[] shapes) {
//在main()中编译正确
public static void maxArea(Shape[]shapes) {
…………
}
}

方法二、先实例化类,然后通过对象调用maxArea()方法也行。

public class ShapeTestb {
public static void main(String[] args) {
Shape[] shapes = new Shape[2];
ShapeTestb st = new ShapeTestb();
st.maxArea(shapes);
}
public void maxArea(Shape[] shapes) {
…………
}
}

“Cannot make a static reference to the non-static method”处理方法的更多相关文章

  1. Cannot make a static reference to the non-static

    public class SeckillServiceImpl implements SeckillService{ private SeckillDao seckillDao; private Su ...

  2. java 中 Cannot make a static reference to the non-static 解决方法

    今天敲代码的时候遇到了这个问题,大体这个问题可以简化成这样: public class Test1 { public String get() { return "123"; } ...

  3. Cannot make a static reference to the non-static method的解决方法

    报错原因:在一个类中写了一个public String getContent()方法和一个main()方法,getContent()方法中包含了getClass()方法,在main()方法中直接调用了 ...

  4. static 类成员变量 和 static const类成员变量

    1.使用static类的优点: (1)避免与其他类的成员或者全局变量冲突 (2)可以封装 (3)阅读性好 2.static 数据成员独立于该类的任意对象而存在 static数据成员的类型可以是该成员所 ...

  5. static与C#中的static

    Static 1.静态方法与非静态方法 a.静态方法的调用类.静态方法名([参数列表]) 非静态方法的调用类 对象 = new 类的构造函数([参数列表])对象.非静态方法名([参数列表]) 静态方法 ...

  6. public static void main(String[] args){} 关于Java main()方法

    是Java程序的入口方法,JVM在运行程序时,会首先查找main()方法. public是权限修饰符,表明任何类或对象都可以访问这个方法: static表明main()方法是一个静态方法,即方法中的代 ...

  7. java中static特殊性和final(static成员直接被访问,this不能用在static方法中,static不可访问非static)

    java的static关键字 java中,static修饰的成员变量和成员方法叫静态变量和静态方法,不依赖类特定的实例,被类的所有实例共享. 静态变量或类变量 和 实例变量,区别是: 静态变量在内存中 ...

  8. Java关键字final、static使用总结 (final static在容器中不可以改变容器但可以改变存放)

    一.final        根据程序上下文环境,Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量.你可能出于两种理解而需要阻止改变:设计或效 ...

  9. java中静态代码块的用法 static用法详解和static静态导入

    (一)java 静态代码块 静态方法区别一般情况下,如果有些代码必须在项目启动的时候就执行的时候,需要使用静态代码块,这种代码是主动执行的;需要在项目启动的时候就初始化,在不创建对象的情况下,其他程序 ...

随机推荐

  1. 关于*[pylint]E1101:Module 'xxx' has no 'xxx' member* 简单而有效的解决办法

    关于 pylint 的 *E1101* 错误: 概念: %s %r has no %r member Function %r has no %r member Variable %r has no % ...

  2. Spring Boot 是什么?

    Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,那么, Spring Boot 诞生的背景是什么?Spring 企业又是基于什么样的考虑创建 Spring Boot ...

  3. hdu-5889-最短路+网络流/最小割

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  4. 码云插件Gitee:Couldn't get the list of Gitee repositories

    20:02 Couldn't get the list of Gitee repositories Can't get available repositories Not Found

  5. python中eval()和json.dumps的使用

    在python中通过requests.get(url)获取json数据,此时可能需要eval进行解析. # -*- coding: utf-8 -*- import requests r = requ ...

  6. Binary Analysis Tool安装使用教程

    Binary Analysis Tool(BAT)是一个用于检测二进制文件使用到的开源组件,协助及早发现程序发布后可能会面临的开源协议解执的开源免费检测工具. 一.安装BAT和bat-extratoo ...

  7. MVC的前端和后端的Model Binding

    1.前端提交JSON 字符串 {"id":13,"title":"这里是标题33","day":"2018-8 ...

  8. 把旧系统迁移到.Net Core 2.0 日记(6) MapRoute/Area/ViewPath

    我想实现 http://localhost:5000/{moduleName}/{controller}/{action}/{id?} 这样的url. 有2个方法 方法1: 在路由里设置多个modul ...

  9. pycharm 配置使用

    1. 如何添加Package File-> Settings -> Project :XXXX -> Project Interpreter 点右边的"+"号,输 ...

  10. JAVA常识1

    DBA:                     https://baike.baidu.com/item/%E6%95%B0%E6%8D%AE%E5%BA%93%E7%AE%A1%E7%90%86% ...