继承英雄的java代码 java继承程序简单例子
写一个最简单的JAVA继承代码??谢谢
可运行的:
创新互联建站主营张家港网站建设的网络公司,主营网站建设方案,重庆APP开发,张家港h5成都微信小程序搭建,张家港网站营销推广欢迎张家港等地区企业咨询
import java.awt.*;
import java.awt.event.*;
public class BackJFrame extends Frame{
public BackJFrame(){
super("台球");
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();
}
}
用java编写一个小程序
abstract class VirtualLife{
int lifeValue;
int attackPowe;
int describe;
public abstract void physicalAttack();
}
abstract class VirtualHero extends VirtualLife{
int defense;
int armor;
}
interface ISkill{
void skillFirst();
void skillSecond();
void skillThird();
void skillFourth();
}
class Ezreal extends VirtualHero implements ISkill{
String hero ="Ezreal";
public void physicalAttack() {
System.out.println(hero+"物理攻击为"+attackPowe);
}
public void skillFirst() {
System.out.println(hero+"使用了技能"+1);
}
public void skillSecond() {
System.out.println(hero+"使用了技能"+2);
}
public void skillThird() {
System.out.println(hero+"使用了技能"+3);
}
public void skillFourth() {
System.out.println(hero+"使用了技能"+4);
}
}
class Annie extends VirtualHero implements ISkill{
String hero ="Annie";
public void physicalAttack() {
System.out.println(hero+"物理攻击为"+attackPowe);
}
public void skillFirst() {
System.out.println(hero+"使用了技能"+1);
}
public void skillSecond() {
System.out.println(hero+"使用了技能"+2);
}
public void skillThird() {
System.out.println(hero+"使用了技能"+3);
}
public void skillFourth() {
System.out.println(hero+"使用了技能"+4);
}
}
class Soliders extends VirtualLife{
public void physicalAttack() {
System.out.println("我是小兵,我的攻击力为"+attackPowe);
}
}
public class Test {
public static void main(String[] args){
Ezreal ezreal=new Ezreal();
ezreal.attackPowe=10;
ezreal.physicalAttack();
Annie annie=new Annie();
annie.attackPowe=20;
annie.physicalAttack();
Soliders solider=new Soliders();
solider.attackPowe=5;
solider.physicalAttack();
}
}
JAVA继承问题 求代码
第一个:
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 + "]";
}
}
第二个类
public class Zhizhujing extends Yaojing {
public void buildNet(){
System.out.println("蜘蛛在织网");
}
}
第三个类
public class Baigujing extends Yaojing {
public void beBeauty(){
System.out.println("白骨精");
}
}
当前标题:继承英雄的java代码 java继承程序简单例子
文章位置:http://azwzsj.com/article/doeissj.html