java继承的最简单代码 java继承的最简单代码是多少

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转型方面的资料

class Vehicle{

protected void vehicleRun(){

System.out.println("vehicle!!!");

}

}

class Truck extends Vehicle{

//子类覆写父类“vehicleRun方法”

protected void vehicleRun(){

System.out.println("It's Truck!!!");

}

protected void truckRun(){

System.out.println("truck!!!");

}

}

class Test{

public static void main(String [] args){

Vehicle v = new Vehicle();

v.vehicleRun(); //父类方法

//向上转型

Vehicle v1 = new Truck();

v1.vehicleRun(); //子类覆写后方法

//向下转型

Truck t = (Truck)v1;

t.vehicleRun();

t.truckRun();

}

}

用Java继承和多态实现编写代码

代码如下:

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();

}

}

java多层继承,简单一点

Java代码:

class Point {

protected int x;

protected int y;

public Point(int x, int y) {

this.x = x;

this.y = y;

}

}

class Circle extends Point {

protected int radius;

public Circle(int x, int y, int radius) {

super(x, y);

this.radius = radius;

}

public double area() {

return Math.PI * radius * radius;

}

public double perimeter() {

return 2 * Math.PI * radius;

}

}

class Cylindar extends Circle {

protected int height;

public Cylindar(int x, int y, int radius, int height) {

super(x, y, radius);

this.height = height;

}

public double volumn() {

return area() * height;

}

}

public class Main {

public static void main(String[] args) {

Point p1 = new Point(3, 4);

Point p2 = new Point(5, 6);

Circle c1 = new Circle(0, 0, 3);

Cylindar cy1 = new Cylindar(0, 0, 3, 4);

System.out.println("圆c1的面积:" + c1.area());

System.out.println("圆c1的周长:" + c1.perimeter());

System.out.println("圆柱体cy1的体积:" + cy1.perimeter());

}

}

运行测试:

圆c1的面积:28.274333882308138

圆c1的周长:18.84955592153876

圆柱体cy1的体积:18.84955592153876

java 类的继承,求大神给代码

public class JIhe {

private String color;

private String dateCreated;

private String filled;

public String getColor() {

return color;

}

public String getDateCreated() {

return dateCreated;

}

public String getFilled() {

return filled;

}

public void setColor(String color) {

this.color = color;

}

public void setFilled(String filled) {

this.filled = filled;

}

@Override

public String toString() {

return "Color:" + this.color +" filled:" + this.filled + "detaCreated:" + dateCreated;

}

}

------------------------------------------------------------------------------------------------------------

public class Circle extends JIhe {

private double radius;

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

public double getArea() {

return 3.14 * this.radius * this.radius;

}

public double getPerimeter() {

return 2 * 3.14 * this.radius;

}

public double getDiameter() {

return 2 * this.radius;

}

}

-----------------------------------------------------------------------------------------------------

public class Rectangle extends JIhe {

private double width;

private double height;

public double getWidth() {

return width;

}

public void setWidth(double width) {

this.width = width;

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double getArea(){

return this.width * this.height;

}

public double getPerimeter(){

return this.width * 2 + this.height * 2;

}

}

——————————————————————————————————————

public class Test {

public static void main(String[] args){

Circle circle = new Circle();

circle.setRadius(1.0);

System.out.println(circle.getArea());

System.out.println(circle.getColor());

System.out.println(circle.getDateCreated());

System.out.println(circle.getDiameter());

System.out.println(circle.getFilled());

System.out.println(circle.getPerimeter());

System.out.println(circle.getRadius());

Rectangle r = new Rectangle();

r.setHeight(2.0);

r.setWidth(4.0);

System.out.println(r.getArea());

System.out.println(r.getColor());

System.out.println(r.getDateCreated());

System.out.println(r.getFilled());

System.out.println(r.getHeight());

System.out.println(r.getPerimeter());

System.out.println(r.getWidth());

}

}

写一个最简单的JAVA继承代码??谢谢

可运行的:

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继承的最简单代码 java继承的最简单代码是多少
文章URL:http://scjbc.cn/article/docjdpp.html

其他资讯