可運(yùn)行的:

門頭溝ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
import java.awt.*;
import java.awt.event.*;
public class BackJFrame extends Frame{
public BackJFrame(){
super("臺(tái)球");
setSize(300,300);
setBackground(Color.cyan); //背景
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent e)
{System.exit(0);}
} );
}
public static void main(String args[]){
new BackJFrame();
}
}
第一個(gè):
public?class?Yaojing?{
protected?String?name;
protected?int?age;
protected?String?gender;
public?void?showBasicInfo()?{
System.out.println(toString());
}
public?void?eatTangSeng()?{
System.out.println("吃飽了");
}
@Override
public?String?toString()?{
return?"Yaojing?[name="?+?name?+?",?age="?+?age?+?",?gender="?+?gender?+?"]";
}
}
第二個(gè)類
public?class?Zhizhujing?extends?Yaojing?{
public?void?buildNet(){
System.out.println("蜘蛛在織網(wǎng)");
}
}
第三個(gè)類
public?class?Baigujing?extends?Yaojing?{
public?void?beBeauty(){
System.out.println("白骨精");
}
}
js繼承有5種實(shí)現(xiàn)方式:
1、繼承第一種方式:對(duì)象冒充
function Parent(username){
this.username = username;
this.hello = function(){
alert(this.username);
}
}
function Child(username,password){
//通過以下3行實(shí)現(xiàn)將Parent的屬性和方法追加到Child中,從而實(shí)現(xiàn)繼承
//第一步:this.method是作為一個(gè)臨時(shí)的屬性,并且指向Parent所指向的對(duì)象,
//第二步:執(zhí)行this.method方法,即執(zhí)行Parent所指向的對(duì)象函數(shù)
//第三步:銷毀this.method屬性,即此時(shí)Child就已經(jīng)擁有了Parent的所有屬性和方法
this.method = Parent;
this.method(username);//最關(guān)鍵的一行
delete this.method;
this.password = password;
this.world = function(){
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi","123456");
parent.hello();
child.hello();
child.world();
2、繼承第二種方式:call()方法方式
call方法是Function類中的方法
call方法的第一個(gè)參數(shù)的值賦值給類(即方法)中出現(xiàn)的this
call方法的第二個(gè)參數(shù)開始依次賦值給類(即方法)所接受的參數(shù)
function test(str){
alert(this.name + " " + str);
}
var object = new Object();
object.name = "zhangsan";
test.call(object,"langsin");//此時(shí),第一個(gè)參數(shù)值object傳遞給了test類(即方法)中出現(xiàn)的this,而第二個(gè)參數(shù)"langsin"則賦值給了test類(即方法)的str
function Parent(username){
this.username = username;
this.hello = function(){
alert(this.username);
}
}
function Child(username,password){
Parent.call(this,username);
this.password = password;
this.world = function(){
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi","123456");
parent.hello();
child.hello();
child.world();
3、繼承的第三種方式:apply()方法方式
apply方法接受2個(gè)參數(shù),
A、第一個(gè)參數(shù)與call方法的第一個(gè)參數(shù)一樣,即賦值給類(即方法)中出現(xiàn)的this
B、第二個(gè)參數(shù)為數(shù)組類型,這個(gè)數(shù)組中的每個(gè)元素依次賦值給類(即方法)所接受的參數(shù)
function Parent(username){
this.username = username;
this.hello = function(){
alert(this.username);
}
}
function Child(username,password){
Parent.apply(this,new Array(username));
this.password = password;
this.world = function(){
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi","123456");
parent.hello();
child.hello();
child.world();
4、繼承的第四種方式:原型鏈方式,即子類通過prototype將所有在父類中通過prototype追加的屬性和方法都追加到Child,從而實(shí)現(xiàn)了繼承
function Person(){
}
Person.prototype.hello = "hello";
Person.prototype.sayHello = function(){
alert(this.hello);
}
function Child(){
}
Child.prototype = new Person();//這行的作用是:將Parent中將所有通過prototype追加的屬性和方法都追加到Child,從而實(shí)現(xiàn)了繼承
Child.prototype.world = "world";
Child.prototype.sayWorld = function(){
alert(this.world);
}
var c = new Child();
c.sayHello();
c.sayWorld();
5、繼承的第五種方式:混合方式
混合了call方式、原型鏈方式
function Parent(hello){
this.hello = hello;
}
Parent.prototype.sayHello = function(){
alert(this.hello);
}
function Child(hello,world){
Parent.call(this,hello);//將父類的屬性繼承過來
this.world = world;//新增一些屬性
}
Child.prototype = new Parent();//將父類的方法繼承過來
Child.prototype.sayWorld = function(){//新增一些方法
alert(this.world);
}
var c = new Child("zhangsan","lisi");
c.sayHello();
c.sayWorld();
代碼如下:
abstract?class?DongWu?{
public?abstract?void?info();
}
class?Bird?extends?DongWu?{
@Override
public?void?info()?{
System.out.println("我是一只鳥。");
}
}
class?Fish?extends?DongWu?{
@Override
public?void?info()?{
System.out.println("我是一條魚。");
}
}
public?class?App5?{
public?static?void?main(String[]?args)?{
DongWu?bird?=?new?Bird();
bird.info();
DongWu?fish?=?new?Fish();
fish.info();
}
}
變量相同字父類不會(huì)被覆蓋,而方法相同子類會(huì)覆蓋父類方法,java在調(diào)用方法時(shí)會(huì)調(diào)用實(shí)際new時(shí)對(duì)象的方法,new Student 那么如果Student中有fun則調(diào)用,沒有才查找父類中有沒有fun方法,而屬性會(huì)直接根據(jù)引用調(diào)用,引用是Person,就調(diào)用Person的i,寫程序時(shí)是根據(jù)引用來寫的,所以不可能你引用Person,會(huì)寫出子類的屬性,比如Student有個(gè)自己的屬性j,你通過to肯定找不到j(luò),如果引用是Student則調(diào)用Student的i,
當(dāng)前文章:繼承java代碼 java 的繼承
文章源于:http://chinadenli.net/article32/hipgpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站設(shè)計(jì)公司、標(biāo)簽優(yōu)化、云服務(wù)器、外貿(mào)建站、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)