本文介绍了这是否正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个由三个类A,B和C组成的程序,这样B

扩展A和C扩展B.每个类应该定义一个instanee variabie

命名为x(也就是说,每个bas都有自己的变量名为x)。在C语言中描述一种方法,用于访问并将A的x版本设置为给定的价值,而不需要更改B或C版本的





calss第一名

Write a program that consists of three classes, A, B, and C, such that B
extends A and C extends B. Each class should define an instanee variabie
named "x" (that is, each bas its own variabie named x). Describe a way for
a method in C to access and set A's version of x to a given vaiue, without
changing B or C's version.

calss number one

public class A {

    public static int a_variable;

    public A ()
    {}

    public void setvariable(int a ){

         a_variable = a ;
    }

    public void getvariable(){

        a_variable = 10;

        System.out.println();

    }

}


class number  two


public class B extends A {

	protected static double b_variable ;

	public B(double b){

		super();
	}

	public void setvalue(double b){

		b_variable = b;
	}

}
class number three


public class C extends B{

	private static int c_variable ;

	public C(){

		super(b_variable);

	}

	@Override
	public void getvariable() {
		super.getvariable();
	}

}

推荐答案


这篇关于这是否正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 03:37