Java 怎样实现调用其他方法
Java主类的main方法调用其他方法
方法1: funA()方法设为静态方法。 当主类加载到内存,funA()分配了入口地址,主要代码如下:
public class test{
static void funA(){
System.out.println("we are students");
}
public static void main(String args[]){
System.out.println("Hello, 欢迎学习JAVA");
funA(); //使用静态方法
}
}
方法2: class A与 主类并列,如下
public class testDemo {
/*
* 成绩统计
* */
public static void main(String[] args) {
Integer[] chinaScore = {,,,,};
int count=;
//合计值
for(int i = ;i<chinaScore.length;i++) {
count+=chinaScore[i];
}
System.out.println("总成绩:"+count); //平均值
int scoreAvg = count/chinaScore.length;
System.out.println(scoreAvg); //保留2位小数
DecimalFormat df = new DecimalFormat(".00");
System.out.println(df.format(scoreAvg)); //最大值 int min = (int) Collections.min(Arrays.asList(chinaScore));
int max = (int) Collections.max(Arrays.asList(chinaScore));
System.out.println("历史最高分:" + max);
funA();//调用
testClass otherFun = new testClass();//使用外部类
otherFun.vo();
} /*
* 自定义funA()函数静态方法
* **/
static void funA() {
System.out.println("we are students");
}
} //class A与 主类并列,main方法中调用其他类的函数
class testClass{
void vo() {
System.out.println("你很帅");
}
}
方法3:A a=new test().new A(); 内部类对象通过外部类的实例对象调用其内部类构造方法产生
public class test{
class A{
void fA(){
System.out.println("we are students");
}
}
public static void main(String args[]){
System.out.println("Hello, 欢迎学习JAVA");
A a=new test().new A(); //使用内部类
a.fA();
}
}
Java 怎样实现调用其他方法的更多相关文章
- 关于Java中子类调用父类方法
当一个类继承于另一个类,子类中没有父类的方法时.用子类的对象调用方法时,会首先在子类中查找,如果子类中没有改方法,再到父类中查找. 当一个方法只在父类中定义时,调用该方法时会使用父类中的属性. 如果该 ...
- java 多态 ---父类调用子类方法
package test1;//多态的体现import javax.print.attribute.standard.RequestingUserName;import java.util.Scann ...
- Java学习----到底调用哪一个方法(多态)
public class Father { public void print() { System.out.println("Father:print()"); } } publ ...
- java泛型类型变量能调用的方法
public class Person { } public class Student extends Person{ private String name; public Student(Str ...
- Java反射机制调用私有方法
1.获取目标类: 每个类都有一个class属性,通过实体类的class属性获取: Class clazz = Person.class 通过对象获取. Person p1 = new Person( ...
- java高级用法之:调用本地方法的利器JNA
目录 简介 JNA初探 JNA加载native lib的流程 本地方法中的结构体参数 总结 简介 JAVA是可以调用本地方法的,官方提供的调用方式叫做JNI,全称叫做java native inter ...
- 【Unity】Unity中C#与Android中Java的互相调用遇到的一些问题
1.有关调用的一些问题: (1).在C#中直接调用java中的代码,无返回值: 在java中: public static void setAge(Context context , int leve ...
- paip。java 高级特性 类默认方法,匿名方法+多方法连续调用, 常量类型
paip.java 高级特性 类默认方法,匿名方法+多方法连续调用, 常量类型 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http ...
- java调用本地方法的时候报错 could not find the main class:xx.program will exit
如图所示,当在java调用本地方法的时候报错 我的解决办法是把dll文件放到System.out.println(System.getProperty("java.library.path& ...
随机推荐
- 利用NHibernate与MySQL数据库交互
本文章使用Visual Studio作为开发工具,并建立在已经安装MySQL数据库的前提. NHibernate是一个面向.NET环境的对象/关系数据库映射工具.官网:http://nhibernat ...
- 去掉Word 标题编号变成黑框
问题: 在使用Word编写文档时,提前拟好的标题编号会突然变成黑框(黑色的方框,黑色的矩形),如下图 解决方案: 1.将光标定位到标题中,紧邻黑框的右侧 2.按键盘左方向键使方框变成黑色 3.按键盘的 ...
- 使用Beyond Compare作为Perforce默认的文件比较工具
使用perforce自带的文件比较工具有时候会遇到乱码的情况,如下: 暂时不知道如何解决上述问题,因此想换个文件比对工具,比如Beyond Compare. 设定位置:Edit->prefere ...
- 2019 牛客多校第一场 E ABBA
题目链接:https://ac.nowcoder.com/acm/contest/881/E 题目大意 问有多少个由 (n + m) 个 ‘A’ 和 (n + m) 个 ‘B’,组成的字符串能被分割成 ...
- 2016CCPC杭州现场赛 B-Bomb /// tarjan缩点
题目大意: 给定n个爆破点的信息 x y r w 表示爆破点位置为 (x,y) 爆破范围是以位置为圆心 半径为r的圆 引爆这个点的代价为w 引爆某个点时 其他位置在该爆破范围内的爆破点也会被引爆 求引 ...
- Oracle学习01-Oracle的基本查询和过滤排序
- 【ArcObject】 AxTocControl:实现图层可移动
设置axTocControl属性:EnableLayerDragDrop 为true即可
- shell 脚本999乘法表
99乘法表 vi st.sh 编辑一个脚本 chmod 777 st.sh 修改权限 注意调整空格,否则打印不出效果 执行脚本 ./st.sh 打印结果
- Font Awesome (Mark)
Font Awesome为您提供可缩放的矢量图标,您可以使用CSS所提供的所有特性对它们进行更改,包括:大小.颜色.阴影或者其它任何支持的效果. 一个字库,675个图标 仅一个Font Awesome ...
- bcolz
raise Exception("this is an ex") bcolz总结: 0.需要用bcolz的columns需要为ndarray的列,不能直接拿list去赋值,因为我发 ...