1. java继承多态的练习题

Java继承来是使用已存在的自类的定义作为基础建立新类的技术,新类的定义可以增加新的数据或新的功能,也可以用父类的功能,但不能选择性地继承父类。
java多态存在的三个必要条件:
1.需要有继承关系的存在
2.需要有方法的重写
3.需要有父类的引用指向子类对象
希望对你有帮助。
第一题应该选D,第二题选C,D。
第一题属于多态,methodB()方法属于子类,父类没有重写子类的方法
第二题属于继承,子类可以继承父类的方法

2. 求 JAVA传参、继承、多态、接口练习题

JAVA传参、继承、多态、接口其实这个东西没有什么练习题的。都是概念性回的东西、需要的是答你理解,做练习题不如去想想它们应该怎么做。我当年学习的时候老师讲的很生动,至今都没有忘记。传参:等于拷贝。意思就是说把要传的东西拷贝进来。继承:人是一个大类(父类)、男人、女人是人类的继承(子类)。每个子类都有自己的方法也可以没有,子类可以调用父类所有的方法。多态:还用人举例。比如说人有一个构造函数是吃一碗饭,而在男人这个子类中重载一下父类的构造函数变成吃两碗饭,女人重载一下父类的构造函数变成吃水果。这个就叫做多态接口:接口是抽象的,这个解释比较逗人。你的fuqin欠了一比钱还不清了,难么需要你来还。如果你也还不清的话那么需要你的下一代偿还。也就是说接口定义一个方法但是它并没有实现这个方法那么引入接口的类就会自动的生成这个方法,让你实现它。好了给你解释完了,我也重新温习了一下

3. java 关于继承、多态的练习题

菜鸟的尝试,如果有什么错误和不妥,欢迎指出。

Public class child{

}

Public class error1 extends child(
érror1(){
}

Void testFail(){

}

}

Public class error2 extends child(
érror2(){
}

Void steals(){

}

}

Public class parents{
parents(){

}

Public static void print(child error){
If(error instanceof error1){
Print("谈心")
}

If(error instanceof error2){
Print("挨打")
}
}

Public static void main (string[] args){
Parents parent= new parents();

Error errora1 = new error1();

Error errora2 = new error2();

Parent.print(errora1);

Parent.print(errora2);

}

大概就这样了,纯手机敲出来的,很多语法不对,
但是看下思路还是看出来的。

4. JAVA多态经典例题

System.out.println("1--" + a1.show(b));
a1是A类引用指向A类对象,不存在多态,一定调用A类方法。类方法有两个show(D)和show(A),b是B类引用无法转换为D类引用,但可以转换为A类引用,因此调用show(A),输出A and A。
System.out.println("2--" + a1.show(c));
输出A and A,原因同上。
System.out.println("3--" + a1.show(d));
调用show(D),输出A and D。
System.out.println("4--" + a2.show(b));
a2是A类引用指向B类对象,可能存在多态。b是B类引用无法转换为D类引用,但可以转换为A类引用,因此调用show(A),而B类重写了show(A),因此调用的是重写后的show(A),输出B and A。
System.out.println("5--" + a2.show(c));
同上,C类引用无法转换为D类引用,但可以转换为A类引用,因此调用show(A),输出B and A。
System.out.println("6--" + a2.show(d));

调用show(D),show(D)又调用父类即A类的show(D),输出A and D
System.out.println("7--" + b.show(b));
b是B类引用指向B类对象,不存在多态,一定调用B类方法。B类一共有三个方法:重写自A类的show(A)和show(D),以及新定义的show(B)。show(b)调用show(B)方法,输出B and B
System.out.println("8--" + b.show(c));
C类继承自B类,也调用show(B)方法,输出B and B
System.out.println("9--" + b.show(d));
调用show(D),show(D)又调用父类即A类的show(D),输出A and D

5. java题目,求助,多态。

publicclass多态
{
publicstaticvoidmain(String[]args)
{
.out.println(" ==========java题目,求助,多态!========== ");
init();
}//初始化!
privatestaticvoidinit()
{
Animalf=newFf("菲菲");
Animalj=newJj("静静");
Apa=newAp("阿平",f);

//假设单数双数为换周,换节目表演的话!
for(inti=1;i<=3;i++)
{
if(i%2!=0)
a.setInstanceof(f);
else
a.setInstanceof(j);
a.train();
a.perform();
System.out.println(" ------------------------------------------------- ");
}
}
}
interfaceAnimal
{
voidtrain();
voidperform();
}

{
F(Stringname){this.name=name;}
protectedStringname;
abstractpublicvoidtrain();
abstractpublicvoidperform();
}
classFfextendsF
{
Ff(Stringname){super(name);}
publicvoidtrain()
{
System.out.println(name+":---->天上飞!");
}
publicvoidperform()
{
System.out.println(name+":--->天空翻转飞翔");
}
}
classJjextendsF
{
Jj(Stringname){super(name);}
publicvoidtrain()
{
System.out.println(name+":------------------>水里游");
}
publicvoidperform()
{
System.out.println(name+":----------->水里跳跃");
}
}
classApextendsF
{
privateAnimala;
Ap(Stringname,Animala){super(name);this.a=a;}
voidsetInstanceof(Animala)
{
this.a=a;
}
publicvoidtrain()
{
if(a==null)return;
System.out.println(name+":训练动物");
if(ainstanceofFf)
{
Fff=(Ff)a;
f.train();
}else
{
Jjj=(Jj)a;
j.train();
}
}
publicvoidperform()
{
if(a==null)return;

System.out.println("特技展示:");

if(ainstanceofFf)
{
Fff=(Ff)a;
f.perform();
}else
{
Jjj=(Jj)a;
j.perform();
}
}
}

6. 求java关于面向对象与继承多态习题·各种·最好是有代表性的·

你只看到它们的形 而没理解它们在实际项目中的用途,所以学起来很苦闷

建议你去看看专 《大属话设计模式》《设计模式之禅》两本书,学设计模式是面向对象编程的一种快速入门的方法

理解设计模式后,你就知道继承 接口 多态这些东西 要如何用 为什么要这样用了

7. Java类的多态练习

public class Exam
{
public static void main(String[] args)
{
(Shape s : new Shape[] {new Rectangle(8,6),new Circle(10)})
{
System.out.println(s.getDescription());
System.out.println(String.format("面积:%.1f",s.getArea()));
}
}
}

abstract class Shape
{
abstract String getDescription();
abstract double getArea();
}

class Rectangle extends Shape
{
Rectangle(double l,double w)
{
length=l;
width=w;
}
public String getDescription()
{
return String.format("长为%.1f,宽为%.1f的长方形!",length,width);
}
public double getArea()
{
return length*width;
}
private double length,width;
}

class Circle extends Shape
{
Circle(double r)
{
radius=r;
}
public String getDescription()
{
return String.format("半径为%.1f的圆!",radius);
}
public double getArea()
{
return Math.PI*radius*radius;
}
private double radius;
}

8. java 多态练习的编程!!!

public class ShapeTextDrive {
//图形随机算法
//随机1,2,3.
//一圆,二方,三阿米巴。
public static Shape getShapeByRandom() {

double num = (int)(Math.random()*3+1); //取1或2或3的随机数
if(num == 1) {
return new Circle();
}else if (num == 2){
return new Square();
}else if(num == 3) {
return new Ameba();
}
return null;
}

public static void main(String[] args) {
//随机取一个实现shape接口的图形实例
Shape shape = ShapeTextDrive.getShapeByRandom();

//传入实例,输出计算结果。
ShapeTextDrive.getCircumferenceAndArea(shape);

//传入circle实例,输出计算结果。
//ShapeTextDrive.getCircumferenceAndArea(new Circle());

}
public static void getCircumferenceAndArea(Shape shape) {
shape.getCircumference();
shape.getArea();
}

//不使用接口的新增方法。
public static void getCircumferenceAndArea(Circle circle) {
circle.getCircumference();
circle.getArea();
}
}

//定义计算周长和面积方法的接口
interface Shape {
abstract double getCircumference();
abstract double getArea();
}

class Circle implements Shape {
public double getCircumference() {
//TODO:
System.out.println("计算圆的周长");
return -1;
}

public double getArea() {
//TODO:
System.out.println("计算圆的面积");
return -1;
}
}

class Square implements Shape {
public double getCircumference() {
//TODO:
System.out.println("计算方的周长");
return -1;
}

public double getArea() {
//TODO:
System.out.println("计算方的面积");
return -1;
}
}

class Ameba implements Shape {
public double getCircumference() {
//TODO:
System.out.println("计算阿米巴形状的周长");
return -1;
}

public double getArea() {
//TODO:
System.out.println("计算阿米巴形状的面积");
return -1;
}
}

9. 一个关于java 的多态题目怎么编程

你好!很高兴为你解答。
借鉴了楼上,认为楼上讲得不够体现,虽然核心代码编了出来了,但没能讲到多态的点子上。我稍作修改,楼主请看:
运行结果:
********************
汽车在行驶
摩托车在行驶
自行车在行驶
************代码如下*************

package TestPolymorphism;

/**
*
* @author 叶科良,568145421
*/
public class TestPolymorphism {

public static void main(String[] args) {
TravelTool travelTool = new Car();
travelTool.run();//一样的语句,不一样的功能,改动处则少
travelTool = new Moto();
travelTool.run();//一样的语句,不一样的功能,改动处则少
travelTool = new Bike();
travelTool.run();//一样的语句,不一样的功能,改动处则少
}
}

abstract class TravelTool {

abstract void run() ; //行驶

abstract void stop(); //刹车
}
class Car extends TravelTool {

void run() {
System.out.println("汽车在行驶");
}

void stop() {
System.out.println("汽车在刹车");
}
}

class Moto extends TravelTool {

void run() {
System.out.println("摩托车在行驶");
}

void stop() {
System.out.println("摩托车在刹车");
}
}

class Bike extends TravelTool {

void run() {
System.out.println("自行车在行驶");
}

void stop() {
System.out.println("自行在刹车");
}
}

10. java多态性的编程题目

publicclassPeople{
privateStringname;
privateIntegerage;
privateStringphone;
publicStringgetMessage(){
"People:姓名:"+name+",年龄:"+age+",电话:"+phone;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicIntegergetAge(){
returnage;
}
publicvoidsetAge(Integerage){
this.age=age;
}
publicStringgetPhone(){
returnphone;
}
publicvoidsetPhone(Stringphone){
this.phone=phone;
}
}
{
privateIntegerid;

publicStringgetMessage(Integerid){
return"Student:姓名:"+super.getName()+",年龄:"+super.getAge()+",电话:"+super.getPhone()+",学号:"+id;
}

publicIntegergetId(){
returnid;
}

publicvoidsetId(Integerid){
this.id=id;
}

}
publicclassS{

publicstaticvoidmain(String[]args){
Studentstudent=newStudent();
student.setId(13);
student.setName("李三");
student.setAge(18);
student.setPhone("123-4567-8901");
System.out.println(student.getMessage(student.getId()));
}

}