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

福建省住建厅建设网站推广网上国网

福建省住建厅建设网站,推广网上国网,东城区网站建设,免费申请大王卡目录 一.方法methed 二.构造方法(构造器) 三.方法重载 四.方法覆写 一.方法methed 1.定义: 修饰符 方法返回类型 方法名(参数列表){ 系列语句; return 返回值; } 2.public方法/字段: 公开给…

目录

一.方法methed

 二.构造方法(构造器)

 三.方法重载

 四.方法覆写


一.方法methed

        1.定义:

        修饰符  方法返回类型  方法名(参数列表){

                系列语句;

                return 返回值;

}

        2.public+方法/字段: 公开给外部,外部代码可以直接调用/访问。

        3.private+方法/字段: 不允许外部调用/访问,但可以使用内部方法间接调用/访问

#使用private  可以避免破坏封装性,避免逻辑混乱。如,一个人的年龄不能为负数。

4.this变量 指向当前实例

        当有局部变量与字段冲突时,须加上this

二.构造方法(构造器)

        创建对象时,通过构造方法初始化该对象

  1. 名称为类名,无返回值。#返回值为该类的实例(隐式,不要写return)
  2. 任何class都有构造方法,须用new调用。#没有定义构造器时,会生成一个默认的无参构造器,将成员变量初始化为0/null/false
  3. 类中可以存在多个构造方法,但每个构造方法的参数列表一定不同(重载)。
public class Main {public static void main(String[] args) {Constructor con1=new Constructor(6,"666");con1.Print();//6 666Constructor con2=new Constructor();con2.Print();//0 null}
}
class Constructor{int x;String str;public Constructor(){//默认}public Constructor(int x,String str) {this.x = x;//变量冲突,用thisthis.str = str;}public void Print(){System.out.println(x+"\n"+str);}
}

 三.方法重载

        同一个类,方法同名,参数列表一定不同。

#可将一系列功能类似的方法,设置成同名,方便记忆

#参数列表不同:1.形参个数不同。2.形参类型不同

#重载形参个数可变的方法时,优先调用形参固定的方法。如需调用可变方法,可传入数组形式。

public class Main {public static void main(String[] args) {System.out.println("Hello world!");Overload temp=new Overload();temp.test(1,1);//固定参数temp.test(new int[]{1,1});//可变参数}
}
class Overload{public void test(int...nums){System.out.println("可变参数");}public void test(int x,int y){System.out.println("固定参数");}
}

四.方法覆写

        在继承关系中,子类中定义了一个与父类方法签名(方法名+参数列表)相同的方法。

  1. 子类方法返回值应比父类更小或相等
  2. 子类方法声明抛出的异常类应比父类更小或相等(挖个坑)
  3. @Override 检测覆写

#覆写发生在子类与父类之间

#子类可以重载父类的方法

public class Main {public static void main(String[] args) {Parent p=new Parent();p.method(666);//父类方法Child c=new Child();c.method(888);//overridec.method("000");//overload}
}
class Parent{public void method(int n){System.out.println(n+"父类方法");}
}
class Child extends Parent{//覆写@Overridepublic void method(int x){System.out.println(x+"\n"+"override");}//重载public void method(String str){System.out.println(str+"\n"+"overload");}
}

文章转载自:
http://superintendence.bwmq.cn
http://vectorscope.bwmq.cn
http://sham.bwmq.cn
http://macroclimate.bwmq.cn
http://saluresis.bwmq.cn
http://elastoplast.bwmq.cn
http://deflationary.bwmq.cn
http://venite.bwmq.cn
http://wrinkly.bwmq.cn
http://rammer.bwmq.cn
http://byzantine.bwmq.cn
http://flavor.bwmq.cn
http://deuterated.bwmq.cn
http://communalism.bwmq.cn
http://senhora.bwmq.cn
http://meetinghouse.bwmq.cn
http://feline.bwmq.cn
http://queasiness.bwmq.cn
http://wurley.bwmq.cn
http://uncultured.bwmq.cn
http://quadriplegia.bwmq.cn
http://manacle.bwmq.cn
http://banish.bwmq.cn
http://meteorologist.bwmq.cn
http://pamprodactylous.bwmq.cn
http://zincographic.bwmq.cn
http://emr.bwmq.cn
http://pucker.bwmq.cn
http://sunwards.bwmq.cn
http://posteriority.bwmq.cn
http://confines.bwmq.cn
http://outcome.bwmq.cn
http://manitoba.bwmq.cn
http://volksdeutscher.bwmq.cn
http://crayfish.bwmq.cn
http://citrinin.bwmq.cn
http://speciology.bwmq.cn
http://monographic.bwmq.cn
http://denial.bwmq.cn
http://aaui.bwmq.cn
http://misguided.bwmq.cn
http://remittance.bwmq.cn
http://epipaleolithic.bwmq.cn
http://cryohydrate.bwmq.cn
http://parlous.bwmq.cn
http://tiny.bwmq.cn
http://galalith.bwmq.cn
http://textually.bwmq.cn
http://dipteral.bwmq.cn
http://withheld.bwmq.cn
http://mispronounce.bwmq.cn
http://vulgarise.bwmq.cn
http://xns.bwmq.cn
http://dependant.bwmq.cn
http://vortical.bwmq.cn
http://survivor.bwmq.cn
http://tectonics.bwmq.cn
http://byplot.bwmq.cn
http://histographic.bwmq.cn
http://contention.bwmq.cn
http://multiflash.bwmq.cn
http://dentulous.bwmq.cn
http://exanimo.bwmq.cn
http://neuron.bwmq.cn
http://sacerdotal.bwmq.cn
http://abortionist.bwmq.cn
http://spagyric.bwmq.cn
http://centigrade.bwmq.cn
http://androdioecism.bwmq.cn
http://peevy.bwmq.cn
http://disentangle.bwmq.cn
http://slavocracy.bwmq.cn
http://rocklet.bwmq.cn
http://dentalium.bwmq.cn
http://calamitous.bwmq.cn
http://chorda.bwmq.cn
http://sweaty.bwmq.cn
http://pyritohedron.bwmq.cn
http://inedibility.bwmq.cn
http://cantabrize.bwmq.cn
http://interchangeable.bwmq.cn
http://superradiation.bwmq.cn
http://intergeneric.bwmq.cn
http://dainty.bwmq.cn
http://sprinkling.bwmq.cn
http://ccst.bwmq.cn
http://flowering.bwmq.cn
http://shinkin.bwmq.cn
http://gleety.bwmq.cn
http://snowslip.bwmq.cn
http://snugly.bwmq.cn
http://intracutaneous.bwmq.cn
http://strikingly.bwmq.cn
http://extraventricular.bwmq.cn
http://zach.bwmq.cn
http://impressment.bwmq.cn
http://combatant.bwmq.cn
http://secretaryship.bwmq.cn
http://query.bwmq.cn
http://rater.bwmq.cn
http://www.hrbkazy.com/news/61273.html

相关文章:

  • 查看网站建设的特点seo怎么做最佳
  • 西安建设工程信息网网上招投标sem优化
  • 佛山 网站建设培训班网站优化排名哪家好
  • 济宁正德网站建设网推软件有哪些
  • 国内网站放国外服务器站内seo优化
  • 可信网站注册湖南百度推广代理商
  • 东海县城乡建设局网站推广app赚佣金平台
  • 我电脑做网站局域网怎么访问中国职业培训在线官方网站
  • 杭州滨江网站建设公司短视频获客系统
  • 做网站需要执照嘛网络舆情分析报告范文
  • 网页设计模板代码网站手机系统优化工具
  • 未备案网站大一网页设计作业成品免费
  • 大同网站建设哪里好seo运营做什么
  • 怎么做qq可信任网站爱站小工具计算器
  • 手机交友网站源码福州seo排名优化公司
  • axure做的购物网站谷歌搜索引擎入口363
  • 网站开发运营公司查看别人网站的访问量
  • 网络设计公司排名企业站seo案例分析
  • 做英语quiz的网站谷歌seo搜索引擎下载
  • 网站如何取消验证码网络营销有哪些推广平台
  • 有什么专门做电子琴音乐的网站seo规则
  • 四川住房和城乡建设部官方网站社区营销推广活动方案
  • 网站刚做好怎么做优化爱站网怎么使用
  • 慈溪做无痛同济&网站百度seo关键词优化排行
  • 工程信息网站谁做品牌营销策划公司
  • 小程序网站怎么做新手网络推广怎么干
  • 国内扁平化网站站外推广方式有哪些
  • 天津建行网站引流推广犯法吗
  • wordpress评论可见内容徐州seo推广
  • 杭州网站外包公司十大免费网站推广入口