//定义接口InterA
interface InterA
{
void fun();
}
//实现接口InterA的类B
class B implements InterA
{
public void fun()
{
System.out.println(“This is B”);
}
}
//实现接口InterA的类C
class C implements InterA
{
public void fun()
{
System.out.println(“This is C”);
}
}
class Test
{
public static void main(String[] args)
{
InterA a;
a= new B();
a.fun();
a = new C();
a.fun();
}
}
This is B This is C
//定义超类superA
class superA {
int i = 100;
void fun() {
System.out.println(“This is superA”);
}
}
//定义superA的子类subB
class subB extends superA {
int m = 1;
void fun() {
System.out.println(“This is subB”);
}
}
//定义superA的子类subC
class subC extends superA {
int n = 1;
void fun() {
System.out.println(“This is subC”);
}
}
class Test {
public static void main(String[] args) {
superA a;
subB b = new subB();
subC c = new subC();
a = b;
a.fun();
(1)
a = c;
a.fun();
(2)
}
}
This is subB This is subC
//定义接口InterA
interface InterA
{
void fun();
}
//实现接口InterA的类B
class B implements InterA
{
public void fun()
{
System.out.println(“This is B”);
}
}
//实现接口InterA的类C
class C implements InterA
{
public void fun()
{
System.out.println(“This is C”);
}
}
class Test
{
public static void main(String[] args)
{
InterA a;
a= new B();
a.fun();
a = new C();
a.fun();
}
}
This is B This is C
class Base {
public static void staticMethod() {
System.out.println("Base staticMehtod");
}
public void dynamicMehtod() {
System.out.println("Base dynamicMehtod");
}
}
class Sub extends Base {
public static void staticMethod() {
System.out.println("Sub staticMehtod");
}
public void dynamicMehtod() {
System.out.println("Sub dynamicMehtod");
}
}
public class TJ4 {
public static void main(String args[]) {
Base c = new Sub();
c.staticMethod();
c.dynamicMehtod();
}
}
Base staticMehtod Sub dynamicMehtod
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有