import关键字

import介绍:

 

import关键字的使用:(导入类和接口)

import导入

  • 在源文件中显示的使用import结构导入指定包下的类、接口

  • 声明在包的声明和类的声明之间

  • 如果需要导入多个结构,则并行写出即可。

  • 使用xxx.* 的方式可以导入xxx包下所有的类或接口

  • 如果使用的类或接口是本包中定义的,则可以省略import结构

  • 如果使用的类或接口是java.lang包下定义的,则可以省略import结构

  • 在源文件中,使用了不同包下同名的类,其中一个类必须以全类名的方式显示出来

  • com.myobjectoriented011.nonworking.Customer cus01=new com.myobjectoriented011.nonworking.Customer("abraham","goldman");

  • 使用xxx.* 表明可以调用xxx包下的所有结构,但是如果使用的是xxx子包下的结构,仍然需要重新import调用

  • import com.包.类

  • import static:导入指定类或接口中的静态结构:属性或方法// import static java.lang.System.*; // out.println("hello");

 

直接看代码:

package com.myarr.nonworking;

import com.myobjectoriented01.nonworking.Customer;
import com.myobjectoriented011.nonworking.BankCustomerText;
import static java.lang.System.*;
import static java.lang.Math.*;

public class ImportText {
public static void main(String[] args) {

BankCustomerText bank=new BankCustomerText();

Customer cus=new Customer("a","b");

com.myobjectoriented011.nonworking.Customer cus01=new com.myobjectoriented011.nonworking.Customer("abraham","goldman");



                out.println("hello");
                 
                 
                int num=addExact(2, 3);
                out.println(num);
}
}

 

posted @ 2021-03-26 10:14  gAbraham  阅读(255)  评论(0)    收藏  举报