关于Java的一个简单问题
我写作业的时候遇到了一些问题,其实挺简单的,可是我还是不懂,还希望大家帮帮忙啊。急用~~编写两个类Point2D,Point3D来表示二维空间和三维空间的点,(1)Poi...
我写作业的时候遇到了一些问题,其实挺简单的,可是我还是不懂,还希望大家帮帮忙啊。急用~~
编写两个类Point2D,Point3D来表示二维空间和三维空间的点,
(1)Point2D有两个整型成员变量x, y (分别为二维空间的X,Y方向坐标),Point2D的构造方法要实现对其成员变量x, y的初始化。
(2)Point3D是Point2D的直接子类,它有有三个整型成员变量x,y,z (分别为三维空间的X,Y,Z方向坐标),Point3D有两个构造方法:Point3D(int x,int y,int z)和Point3D(Point2D p,int z),两者均可实现对Point3D的成员变量x, y,z的初始化。
Point3d(Point2d p,z)在方法体里面如果写p.,出现的下拉菜单里面并没有x,y,z以及在Point2d里面定义的那些函数啊?这是怎么回事啊?是不是说明不能这样用? 展开
编写两个类Point2D,Point3D来表示二维空间和三维空间的点,
(1)Point2D有两个整型成员变量x, y (分别为二维空间的X,Y方向坐标),Point2D的构造方法要实现对其成员变量x, y的初始化。
(2)Point3D是Point2D的直接子类,它有有三个整型成员变量x,y,z (分别为三维空间的X,Y,Z方向坐标),Point3D有两个构造方法:Point3D(int x,int y,int z)和Point3D(Point2D p,int z),两者均可实现对Point3D的成员变量x, y,z的初始化。
Point3d(Point2d p,z)在方法体里面如果写p.,出现的下拉菜单里面并没有x,y,z以及在Point2d里面定义的那些函数啊?这是怎么回事啊?是不是说明不能这样用? 展开
5个回答
展开全部
大致上这么写。 protected这个type意思是所有子类也可以用这个变量。
class Point2D
{
public Point2D(int x, int y){
this.x = x;
this.y = y;
}
public int getX()
{return this.x;}
public int getY()
{return this.y;}
protected int x;
protected int y;
}
class Point3D extends Point2D
{
public Point3D(int x,int y,int z)
{ super(x, y);
this.z = z;
}
Point3D(Point2D p,int z)
{ this.x = p.getX();
this.y = p.getY();
this.z = z;
}
protected int z;
}
class Point2D
{
public Point2D(int x, int y){
this.x = x;
this.y = y;
}
public int getX()
{return this.x;}
public int getY()
{return this.y;}
protected int x;
protected int y;
}
class Point3D extends Point2D
{
public Point3D(int x,int y,int z)
{ super(x, y);
this.z = z;
}
Point3D(Point2D p,int z)
{ this.x = p.getX();
this.y = p.getY();
this.z = z;
}
protected int z;
}
展开全部
public class Point2D{
int x;
int y;
public Point2D() {
super();
}
public Point2D(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
=========================
public class Point3D extends Point2D {
int z;
Point2D p;
public Point3D(int x, int y, int z) {
super(x, y);
this.z = z;
}
public Point3D(Point2D p,int z){
this.x = p.x;
this.y = p.y;
this.z = z;
}
}
int x;
int y;
public Point2D() {
super();
}
public Point2D(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
=========================
public class Point3D extends Point2D {
int z;
Point2D p;
public Point3D(int x, int y, int z) {
super(x, y);
this.z = z;
}
public Point3D(Point2D p,int z){
this.x = p.x;
this.y = p.y;
this.z = z;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Point2D {
private int x, y;
public Point2D(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {return x;}
public int getY() {return y;}
}
public class Point3D extends Point2D {
private int z;
public Point3D(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3D(Point2D p, int z) {
this.x = p.getX();
this.y = p.getY();
this.z = z;
}
}
private int x, y;
public Point2D(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {return x;}
public int getY() {return y;}
}
public class Point3D extends Point2D {
private int z;
public Point3D(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3D(Point2D p, int z) {
this.x = p.getX();
this.y = p.getY();
this.z = z;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Point2D
{
private int x;
private int y;
protected Point2D()
{
}
public Point2D(int x,int y)
{
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
class Point3D extends Point2D
{
private int z;
private Point3D()
{
}
public Point3D(int x,int y,int z)
{
super(x,y);
this.z = z;
}
public Point3D(Point2D p,int z)
{
super(p.getX(),p.getY());
this.z = z;
}
public int getZ()
{
return z;
}
public void setZ(int z)
{
this.z = z;
}
}
那是因为父类的变量是private的,所以直接用.出来不了。改成public,protected就可以了,但是为了代码的安全性,变量都是使用的private。
{
private int x;
private int y;
protected Point2D()
{
}
public Point2D(int x,int y)
{
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
class Point3D extends Point2D
{
private int z;
private Point3D()
{
}
public Point3D(int x,int y,int z)
{
super(x,y);
this.z = z;
}
public Point3D(Point2D p,int z)
{
super(p.getX(),p.getY());
this.z = z;
}
public int getZ()
{
return z;
}
public void setZ(int z)
{
this.z = z;
}
}
那是因为父类的变量是private的,所以直接用.出来不了。改成public,protected就可以了,但是为了代码的安全性,变量都是使用的private。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.*;
public class Test{
public static void max_min(int a[]){
int b[]= new int [a.length];
int k=0 ,i,j;
for( i=0;i<a.length; i++)
b[i]=a[i];
for( j = 0;j<b.length-1; j++)
for( i = j,k = i ; i<b.length-1 ; i++)
{
if(b[i]<b[i+1])
k= i+1;
}
if(k!=i)
{
int t;
t=a[j];
a[j]=a[k];
a[k]= t;
//交换
}
for( i = 0; i<b.length; i++)
System.out.println(b[i]);
}
public static void main(String args[]){
int list[]= new int[3];
Random rand = new Random();
for(int i = 0; i< list.length; i++ )
{
list[i] = rand.nextInt()%100;
max_min(list);
System.out.println(list[i]);
}
}
}
public class Test{
public static void max_min(int a[]){
int b[]= new int [a.length];
int k=0 ,i,j;
for( i=0;i<a.length; i++)
b[i]=a[i];
for( j = 0;j<b.length-1; j++)
for( i = j,k = i ; i<b.length-1 ; i++)
{
if(b[i]<b[i+1])
k= i+1;
}
if(k!=i)
{
int t;
t=a[j];
a[j]=a[k];
a[k]= t;
//交换
}
for( i = 0; i<b.length; i++)
System.out.println(b[i]);
}
public static void main(String args[]){
int list[]= new int[3];
Random rand = new Random();
for(int i = 0; i< list.length; i++ )
{
list[i] = rand.nextInt()%100;
max_min(list);
System.out.println(list[i]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询