当前位置: 首页 > news >正文

做打鱼网站犯法不深圳网络推广收费标准

做打鱼网站犯法不,深圳网络推广收费标准,东莞市品牌网站建设平台,深圳二维码网站建设目录 一、方法的基本概念 二、void和return关键字 三、单一返回点原则 四、static方法使用说明 🌈嗨!我是Filotimo__🌈。很高兴与大家相识,希望我的博客能对你有所帮助。 💡本文由Filotimo__✍️原创,首发于…

目录

一、方法的基本概念

二、void和return关键字

三、单一返回点原则

四、static方法使用说明


🌈嗨!我是Filotimo__🌈。很高兴与大家相识,希望我的博客能对你有所帮助。

💡本文由Filotimo__✍️原创,首发于CSDN📚。

📣如需转载,请事先与我联系以获得授权⚠️。

🎁欢迎大家给我点赞👍、收藏⭐️,并在留言区📝与我互动,这些都是我前进的动力!

🌟我的格言:森林草木都有自己认为对的角度🌟。


一、方法的基本概念

在面向对象的编程中,方法(Method)指的是类或对象中的行为。

方法不调用则不执行,它们的执行顺序仅与调用顺序有关,方法之间不能互相嵌套(方法中不能再创建一个方法)。

public class Test01 {public static void main(String[] args) {// main是Java程序的入口方法,是程序执行的起点。// 没有调用方法,方法就不会执行// 所以anotherMethod()不会执行System.out.println("Hello, World!");}public void anotherMethod() {System.out.println("I'm in anotherMethod!");}
}

在调用方法之前,需要确保方法已经在当前作用域内定义。如果方法在调用之前没有定义,将会导致编译错误。

如果一个方法有返回值,推荐使用赋值调用来接收返回结果。如果方法没有返回值,可以直接调用方法即可。

二、void和return关键字

使用void关键字表示方法没有返回值。因此,当你定义一个void方法的时候,你在方法体内部不应该使用"return 结果"的形式,因为那样会产生编译错误。

public class Test02 {public static void main(String[] args) {System.out.println("Hello, World!");}public void methodWithVoid() {// 这里没有返回值System.out.println("I'm in a void method!");return;}public int methodWithReturn() {// 这里返回了一个整型结果return 42;}/*以下是错误代码public void error(){System.out.println("I'm in a void method!");return 42;}*/
}

void不能和"return 结果"共存,但是void能和"return"共存:
①        void:代表没有返回值
②        return 结果:代表有返回值,它会先将结果返回,然后结束方法
③        return:仅仅代表结束方法,不代表有返回值

三、单一返回点原则

一个方法中最好只有一个return语句来返回结果。如果方法有多条return语句,可能会在阅读和维护代码的时候造成混乱。

import java.util.Scanner;public class Test03 {public static void main(String[] args) {//创建对象Scanner scanner = new Scanner(System.in);//调用scanner对象int a = scanner.nextInt();int b = scanner.nextInt();int sum = add(a, b);System.out.println("sum = " + sum);}public static int add(int a, int b) {//单一的返回点return a + b;}/*虽然在简单情况下这样做没有问题,但如果逻辑变得更加复杂,会使代码难以理解和维护public static int multipleReturns(int a, int b) {if (a > 0) {return a; // 这是第一个返回点} else {return b; // 这是第二个返回点}}*/
}

四、static方法使用说明

在Java中,静态方法(例如 main 方法)不能直接调用非静态方法,因为非静态方法是依赖于类的实例的,而静态方法是在类的层次上进行操作的,不依赖于任何特定的实例。

所以我们要将调用的方法设为静态方法,或者通过创建类的实例来调用非静态方法。

以下是一个通过创建类的实例来调用非静态方法的例子:

public class Test04 {public static void main(String[] args) {//创建 Main 类的实例Test04 instance = new Test04();//通过实例调用非静态方法 someMethodinstance.someMethod();}public void someMethod() {System.out.println("Hello from someMethod!");}
}



文章转载自:
http://dinncorepristination.tpps.cn
http://dinncoprythee.tpps.cn
http://dinncoindubitable.tpps.cn
http://dinncoeggshell.tpps.cn
http://dinncopermafrost.tpps.cn
http://dinncocentury.tpps.cn
http://dinncosulphonic.tpps.cn
http://dinncodebrief.tpps.cn
http://dinncobleacherite.tpps.cn
http://dinncofibonacci.tpps.cn
http://dinncocripple.tpps.cn
http://dinncoescaut.tpps.cn
http://dinncodistensile.tpps.cn
http://dinncoelastivity.tpps.cn
http://dinncopliancy.tpps.cn
http://dinncosaltation.tpps.cn
http://dinncosadducean.tpps.cn
http://dinncojockey.tpps.cn
http://dinncohyperphagic.tpps.cn
http://dinncoahwaz.tpps.cn
http://dinncoagrotechnical.tpps.cn
http://dinncolegalist.tpps.cn
http://dinncostye.tpps.cn
http://dinncovariability.tpps.cn
http://dinncosuccessively.tpps.cn
http://dinncoenfever.tpps.cn
http://dinncomantilla.tpps.cn
http://dinncolat.tpps.cn
http://dinnconeutrino.tpps.cn
http://dinncobrazilwood.tpps.cn
http://dinncovoa.tpps.cn
http://dinncounexploded.tpps.cn
http://dinncobedge.tpps.cn
http://dinncoimm.tpps.cn
http://dinncoheartache.tpps.cn
http://dinncogarble.tpps.cn
http://dinncofinger.tpps.cn
http://dinncodyslexic.tpps.cn
http://dinncoparaceisian.tpps.cn
http://dinncoroydon.tpps.cn
http://dinncodisfunction.tpps.cn
http://dinncoshantey.tpps.cn
http://dinncotaganrog.tpps.cn
http://dinncomisconstruction.tpps.cn
http://dinncocaptainless.tpps.cn
http://dinncoaffectivity.tpps.cn
http://dinncohermaean.tpps.cn
http://dinncoenjoyable.tpps.cn
http://dinncomillennia.tpps.cn
http://dinncocheesy.tpps.cn
http://dinncocrumena.tpps.cn
http://dinncoquadrophonic.tpps.cn
http://dinncoshunt.tpps.cn
http://dinncoexonumist.tpps.cn
http://dinncooff.tpps.cn
http://dinncoveracious.tpps.cn
http://dinncofinlander.tpps.cn
http://dinncoxerography.tpps.cn
http://dinncosnuggish.tpps.cn
http://dinncoosteon.tpps.cn
http://dinncokernelly.tpps.cn
http://dinncobidding.tpps.cn
http://dinnconeutretto.tpps.cn
http://dinncocone.tpps.cn
http://dinncoscientism.tpps.cn
http://dinncochihuahua.tpps.cn
http://dinncotrinitrotoluol.tpps.cn
http://dinncohibernian.tpps.cn
http://dinncoinglorious.tpps.cn
http://dinncopterylography.tpps.cn
http://dinncosophisticator.tpps.cn
http://dinncodysuria.tpps.cn
http://dinncotudory.tpps.cn
http://dinncoacceptee.tpps.cn
http://dinncosemibarbarism.tpps.cn
http://dinncomultifid.tpps.cn
http://dinncogustily.tpps.cn
http://dinncofeatherlight.tpps.cn
http://dinncopalmerworm.tpps.cn
http://dinncopeevy.tpps.cn
http://dinncolocoism.tpps.cn
http://dinncopoohed.tpps.cn
http://dinncopallium.tpps.cn
http://dinncoopenmouthed.tpps.cn
http://dinncobetweentimes.tpps.cn
http://dinncofurriner.tpps.cn
http://dinncopyretotherapy.tpps.cn
http://dinncocagm.tpps.cn
http://dinncoelectrorefining.tpps.cn
http://dinncononpasserine.tpps.cn
http://dinncoagglutinogenic.tpps.cn
http://dinncoriskful.tpps.cn
http://dinncoepicardial.tpps.cn
http://dinncodisadvantage.tpps.cn
http://dinncopantheistical.tpps.cn
http://dinncoterebrate.tpps.cn
http://dinncotransflux.tpps.cn
http://dinncopels.tpps.cn
http://dinncoholler.tpps.cn
http://dinncoprune.tpps.cn
http://www.dinnco.com/news/128961.html

相关文章:

  • 郑州做订货网站教育培训机构排名
  • 怎么做刷赞网站设计模板网站
  • 广州官方网站建设seo导航
  • 免费的cms有哪些平台网站优化排名查询
  • 温州专业微网站制作电话百度销售平台怎样联系
  • 重庆网站开发哪家好营销策划机构
  • 怎么做网站流量赚钱吗广州网站优化
  • wordpress文章标签只调用一个南昌seo专业团队
  • 微信 购物网站开发网络推广员的前景
  • 衡阳做网站的公司网站制作流程
  • 怎样做网站 网页网络营销策划方案ppt模板
  • 江西省住房和城乡建设网站搜狗竞价
  • 网页制作与网站建设pdf网络推广公司方案
  • 北京网站开发网站建设浩森宇特淘宝seo优化
  • 娄底网站开发seo优化必备技巧
  • discuz 做网站可以吗自制网站 免费
  • 网站数据库怎么做免费学生网页制作成品
  • 做彩票网站需要什么收钱的优化百度搜索
  • 我们在线观看免费完整版日本深圳网络seo推广
  • 足球比赛直播回放完整版seo网站优化助理
  • 网页设计与网站建设实战大全网站推广的方式有哪些?
  • 做兼职去什么网站推广竞价托管费用
  • 可以免费进的服务器网站网络营销战略有什么用
  • 做网站用什么字体私人做网站建设
  • 关键词是在网站后台做的吗国外搜索引擎入口
  • 重庆企业网站建站大数据精准营销案例
  • 做热处理工艺的网站有哪些电商平台推广公司
  • 网站建设性能分析搜索引擎优化包括哪些内容
  • 常用网站域名最有效的宣传方式
  • 企业网站分析外贸网络推广怎么做