package japan.people;
import american.people.Son;
public class Grandson extends Son{
public String foot;
}
package american.people;
import england.people.Father;
public class Son extends Father {
public String hand;
public String getHand(){
return hand;
}
}
package england.people;
public class Father{
private int money;
protected int height;
int weight;
}
package england.people;
import american.people.Son;
import japan.people.Grandson;
public class Example {
public static void main(String[] args) {
Son son =new Son();
Grandson grandson = new Grandson();
son.height = 180;
son.hand = "一双大手";
grandson.height = 155;
grandson.foot = "一双小脚";
String str =son.getHand();
System.out.println("儿子:"+son.hand+"身高:"+son.height);
str = grandson.getHand();
System.out.println("孙子:"+grandson.foot+"身高:"
+grandson.height);
}
}
class People{
public double x;
public void setX(double x){
this.x=x;
}
public double getDoubleX(){
return x;
}
}
class Student extends People{
int x;
public int getX( ){
return x;
}
}
public class 作业二 {
public static void main(String[] args) {
Student stu =new Student();
stu.x=98;
System.out.println("对象stu的x的值是:"+stu.getX());
stu.setX(98.89);
double m =stu.getDoubleX();
System.out.println("对象stu隐藏的x是:"+m);
}
}
class A{
double f(float x,float y){
return x+y;
}
public int g(int x,int y){
return x+y;
}
}
class B extends A{
double f(float x,float y){
return x*y;
}
}
public class 作业三 {
public static void main(String[] args) {
B b=new B();
double result=b.f(5,6);
System.out.println("调用重写方法得到的结果:"+result);
int m=b.g(3,5);
System.out.println("调用继承方法得到的结果:"+m);
}
}
class Student{
int number;
String name;
Student(){
}
Student(int number,String name){
this.number=number;
this.name=name;
}
public int getNumber(){
return number;
}
public String getName(){
return name;
}
}
class UniverStudent extends Student{
boolean isMarriage;
UniverStudent(int number,String name,boolean b){
super(number,name);
}
public boolean getIsMarriage(){
return isMarriage;
}
}
public class 作业四 {
public static void main(String[] args) {
UniverStudent zhang = new UniverStudent(20111, "张三", false);
int number = zhang.getNumber();
String name = zhang.getName();
boolean marriage = zhang.getIsMarriage();
System.out.println(name + "学号是:" + number);
if (marriage == true) {
System.out.println(name + "已婚");
} else {
System.out.println(name + "未婚");
}
}
}
class Sum {
int n;
public double f(){
double sum = 0;
for(int i=1;i<=n;i++){
sum=sum+i;
}
return sum;
}
}
class Average extends Sum{
double n;
public double f(){
double c;
super.n=(int)n;
c=super.f();
return c+n;
}
public double g(){
double c;
c=super.f();
return c-n;
}
}
public class 作业五 {
public static void main(String[] args) {
Average aver=new Average();
aver.n = 100.5678;
double result1 = aver.f();
double result2 = aver.g();
System.out.println("result1="+result1);
System.out.println("result2="+result2);
}
}
class Anthropoid{
double m =12.5;
void crySpeak(String s){
System.out.println(s);
}
}
class People extends Anthropoid{
char m='A';
int n=60;
void computer(int a,int b){
int c=a+b;
System.out.println(a+"加"+b+"等于"+c);
}
void crySpeak(String s){
System.out.println(m+"**"+s+"**"+m);
}
}
public class 作业六 {
public static void main(String[] args) {
People people=new People();
Anthropoid monkey= people;
monkey.crySpeak("I Love this game");
System.out.println(monkey.m);
System.out.println(people.m);
People zhang=(People)monkey;
zhang.computer(55,33);
zhang.m='T';
System.out.println(zhang.m);
}
}
abstract class GrilFriend{
abstract void speak();
abstract void cooking();
}
class ChinaGrilFriend extends GrilFriend {
void speak(){
System.out.println("你好");
}
void cooking (){
System.out.println("水煮鱼");
}
}
class AmericanGrilFriend extends GrilFriend {
void speak(){
System.out.println("hello");
}
void cooking (){
System.out.println("roast beef");
}
}
class Boy {
GrilFriend friend;
void setGrilFriend(GrilFriend f){
friend =f;
}
void showGirlFriend(){
friend.speak();
friend.cooking();
}
}
public class 作业七 {
public static void main(String[] args) {
GrilFriend girl = new ChinaGrilFriend();
Boy boy= new Boy();
boy.setGrilFriend(girl);
boy.showGirlFriend();
girl = new AmericanGrilFriend();
boy.setGrilFriend(girl);
boy.showGirlFriend();
}
}
abstract class Animal {
public abstract void cry();
public abstract String getAnimalName();
}
class Simulator{
public void playSound(Animal animal){
System.out.println("现在播放"+animal.getAnimalName()+"类的声音:");
animal.cry();
}
}
class Dog extends Animal{
public void cry(){
System.out.println("汪汪");
}
public String getAnimalName() {
return "狗";
}
}
class Cat extends Animal{
public void cry(){
System.out.println("喵喵");
}
public String getAnimalName() {
return "猫";
}
}
public class 作业八 {
public static void main(String[] args) {
Simulator simulator = new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
interface Printable{
public static final int MAX = 10;
public abstract void on();
public abstract float sum(float x,float y);
default int max(int a,int b){
return a>b?a:b;
}
public static void f(){
System.out.println("注意是从javaSE8开始的");
}
}
class AAA implements Printable{
public void on(){
System.out.println("打开电视");
}
public float sum(float x,float y){
return x+y;
}
}
public class 作业九 {
public static void main(String[] args) {
AAA a=new AAA();
System.out.println("接口中的常量"+AAA.MAX);
System.out.println("调用on方法(重写的):");
a.on();
System.out.println("调用sum方法(重写的):"+a.sum(12,18));
System.out.println("调用接口提供的default方法"+a.max(12,78));
Printable.f();
}
}
记录一下,下面那个是我人生中第一次写出来的代码。👇👇超级有成就感!!!!
class A{
void f(){
char cc = 97;
for (int i = 0; i < 26; i++) {
char dd=(char)(cc+i);
System.out.println(dd);
}
System.out.println("小写英文字母表");
}
}
class B extends A{
void g(){
char ccc =65;
for (int i = 0; i < 26; i++) {
char ddd=(char)(ccc+i);
System.out.println(ddd);
}
System.out.println("这是大写英文字母表");
}
}
public class abcdef{
public static void main(String[] args) {
B b=new B();
b.f();
b.g();
}
}
下面这个来不及了,从网上找的一个。。。。。
class A{
public int f(int a, int b){
if(b<a){
int temp=0;
temp=a;
a=b;
b=temp
int r=bsa;tr=bx
0){hile(r!=0)
b=a;
a=r;
r=bs
=b8a;
}
return a;
}
}
class B extends A{
public int f(int a,int b) {
int division = super. f(a,b);
return (a* b)/division;
}
public class E{
public static void main (String args[ ]) {
Aa=new A();
System.out.println("最大公约数:"+a.f(36,24
a= new B();
System.out.println("最小公倍数:" + a.f(36,24
}
}