189 8069 5689

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 类的继承,求大神给代码

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继承,子类继承父类,子类是只允许调用父类的代码,还是子类拥有了这些代码

情况是这样的:

Class Two 继承了 Class One ,因此就可以使用 printAB() ,

当执行到 语句: t.printAB(), 时,会跳转到 Class One 中,执行 printAB(),

然后,发现 里面有个 printA(), 于是 去 Class Two中找,因为修饰符为 protected 能被Class One看到,所以 打印 TwoA;

然后,又发现有个 printB() , 于是去Class Two中找,因为修饰符是 private 所以,不能被Class One看到,所以 打印 OneB;

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继承和多态实现编写代码

代码如下:

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继承

public class Inheritance3

{

public static void main(String[] args)

{

Son son = new Son(); // 这里只是实例化Son类所以只能调用Son中的方法

son.son() ;

Father father = new Son() ;//Son是Father的子类 可以通过子类实例化父类

father.father() ; //调用父类中的方法

Grandpa grandpa = new Son() ; //Son是Father的子类,Father是Grandpa的子类,那么Son也是Grandpa的子类

grandpa.grandpa() ;

}

}

class Grandpa

{

public void grandpa()

{

System.out.println("grandpa");

}

}

class Father extends Grandpa

{

public void father()

{

System.out.println("father");

}

}

class Son extends Father

{

public void son()

{

System.out.println("son");

}

}


文章题目:java继承对象代码 java的继承和实现
当前网址:http://jkwzsj.com/article/hhsoep.html

其他资讯