猿问

java中主函数怎么调用类定义中的函数?

import javax.swing.*;
public class DrawTable extends JFrame
{
public DrawTable()
public boolean table()
public static void main(String[]args)
{
}
}
main函数中怎么调用table函数?



慕斯王
浏览 877回答 4
4回答

米脂

public class DrawTable extends JFrame{public DrawTable(){}public boolean table(){}public static void main(String[]args){DrawTable dt = new DrawTable ();dt.table();}}

ibeautiful

package com.cfzy.learn;import javax.swing.JFrame;/*** 画表格** @author 残烽追影* @version 1.0* @created 2012-12-16 下午05:33:27*/public class DrawTable extends JFrame {/** 描述 */private static final long serialVersionUID = 1L;public DrawTable() {}public boolean table() {return rootPaneCheckingEnabled;}public static void main(String[] args) {DrawTable dt = new DrawTable();dt.table();}}

吃鸡游戏

main是静态函数,不可直接调用非静态函数table。要在main中定义一个类的对象才可以调用table方法。在main中用this.table();应该可以

慕桂英4014372

public class DrawTable extends JFrame{public DrawTable(){}public boolean table(){}public static void main(String[]args){DrawTable dt = new DrawTable ();dt.table();}}
随时随地看视频慕课网APP

相关分类

Java
我要回答