这是否正确 [英] This is correct or not

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

问题描述

编写一个由三个类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();
	}
	
}

推荐答案

请参阅我的评论,该评论应直接回答您的问题。



只有一个提示:你甚至没有尝试过这个家庭作业的最基本要求:引入同名的实例变量每个类中的( x 或任何其他内容)。而且,你定义了一些静态变量;而static与实例变量相反。



结论:你根本没有意识到编程的基本概念之一。你应该首先学习这些基础知识,而不是解决这个问题。最好的方法是从一开始就开始阅读一些手册。我保证:这对你很有帮助。



-SA
Please see my comment which should directly answer your question.

Just one hint: you did not even try to meed the most basic requirement of this home assignment: to introduce instance variable of the same name (x or anything) in each of the classes. Moreover, you defined some static variables; and "static" is the opposite to instance variable.

Conclusion: you are simply unaware of one of the basic notions of programming. Instead of solving this problem, you should first learn those basics. The best way to do it is to start reading some manual, pretty much from the very beginning. I'll guarantee: this will really help you a lot.

—SA


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆