• 基础语法


    1.标识符和关键字

      标识符:java程序的组成,⽐如类名、⽅法名、变量名等

      注意点: * 标识符可以由字⺟、数字、下划线_ 、美元符($)组成,但不能包含%,空格等其他 特殊字符,不能以数字开头 * 区分⼤⼩写 * 不能是java关键字

      Java关键字: 是电脑语⾔⾥事先定义的,有特别意义的标识符,有时⼜叫保留字,关键字 不能⽤作变量名、⽅法名、类名、包名和参数

    boolean、bytechardoubleenumfloatintlongshortvoid
    privateprotectedpublicdefaultabstract、extends、classinterfacereturnstatic、super、assert、breakcasetrycatchconstcontinuedoelse、final、finallyforgotoif、implements、import、instanceof、native、new、package、switch、synchronized 、thisthrow、throws、transient、volatilewhile

    2、java修饰符

      访问修饰符:

        限定类、属性或⽅法是否可以被程序⾥的其他部分访问和调⽤的修饰符

        private < default < protected < public

        ⾮访问修饰符:⽤来修饰或者辅助功能,

        例如static、final、abstract、synchronized等

      外部类修饰符: public或者为默认

      ⽅法、属性修饰符:private、default、protected、public

      public - 公开对外部可⻅

      protected - 对包和所有⼦类可⻅

      private - 仅对类内部可⻅

      方法级别

     类

    package chapter4_2;
    
    public class Father {
        protected void test(){
            System.out.println("我是father类的test方法");
            test1();
        }
    
        private void test1(){
            System.out.println("我是father类的test1方法");
        }
    }

    主入口

    package test;
    import chapter4_2.Father;

    //MainTest 作为 Father 的子类
    public class MainTest extends Father{ public static void main(String [] args){ System.out.println("我是MainTest"); MainTest mainTest = new MainTest(); mainTest.test(); } }

      属性或者成员变量,都⽤private修饰,不⽤其他的,这个是java开发的约束

    Java中public class与class的区别

      在⼀个*.java的⽂件中,只能有⼀个public class的声明,有多个public则编译报错,其类名 称必须与⽂件名称完全⼀致,但是允许有多个class的声明,

    public class A{
     public static void main(String [] args){
     System.out.println("A");
     }
    };
    class B{};
    class C{};

    只有public修饰的类,才能在包外部包可⻅;否则只是包内私有的类,类不能被其他包访 问。

    dayehui
  • 相关阅读:
    JavaScript的由来, 浏览器的20年
    WEB界面onload前的加载流程❤❤
    HTML5文件系统API和资料整理
    No enclosing instance of type is accessible. Must qualify the allocation with an enclosing instance of type LeadRestControllerTest (e.g. x.new A() where x is an instance of ).
    Git Gerrit Code Review
    Nginx Configuring HTTPS servers
    自签名证书 nginx tomcat
    centos yum install nginx
    局域网 服务器 https
    分布式重复提交
  • 原文地址:https://www.cnblogs.com/zrh-960906/p/13973358.html
Copyright © 2020-2023  润新知