为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
Java入门第二季_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

Java入门第二季

IMOOC老齐 全栈工程师
难度入门
时长 4小时 0分
  • 访问修饰符的使用:https://img1.sycdn.imooc.com//5b21d151000101b210590301.jpg

    查看全部
  • 如果没有父类,默认父类是object类

    查看全部
  • 如果写了有参的构造方法,系统就不会帮我们生成无参的构造方法.

    查看全部
  • 执行顺序笔记

    查看全部
  • 静态内部类不能直接访问外部类的非静态成员,但可以通过 new 外部类().成员 的方式访问

    //外部类
    public class HelloWorld {
        
        // 外部类中的静态变量score
        private static int score = 84;
        private int score2=100;
        
        // 创建静态内部类
        public static class SInner {
            // 内部类中的变量score
            int score = 91;
            
            public void show() {
                System.out.println("访问外部类中的score:" + new HelloWorld().score2);
                System.out.println("访问内部类中的score:" + score);
            }
        }

        // 测试静态内部类
        public static void main(String[] args) {
            // 直接创建内部类的对象
            SInner si=new SInner();
            
            // 调用show方法
            si.show();
        }
    }

    查看全部
  • KEY WORD: this

    代表当前对象,不是当前类

    查看全部
  • // 创建外部类对象
    HelloWorld hello = new HelloWorld();

    // 创建内部类对象
    Inner i = hello.new Inner();

     // 调用内部类对象的方法
     i.show();

    查看全部
  • JAVA 访问修饰符

    查看全部
  • 4. 包的使用
    查看全部
  • JAVA中的包

    Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc.

    A Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations ) providing access protection and namespace management.

    查看全部
  • 封装实现的步骤


    Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction.

    Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.

    To achieve encapsulation in Java −

    • Declare the variables of a class as private.

    • Provide public setter and getter methods to modify and view the variables values.


    查看全部
  • JAVA 代码块 https://www.cnblogs.com/chenssy/p/3413229.html

    查看全部
  • 静态方法中可以直接调用同类中的静态成员,但不能直接调用非静态成员。如果希望在静态方法中调用非静态变量,可以通过创建类的对象,然后通过对象来访问非静态变量。

    在普通成员方法中,则可以直接访问同类的非静态变量和静态变量,

    静态方法中不能直接调用非静态方法,需要通过对象来访问非静态方法。

    public class HelloWorld {
        
        // 定义变量score1
        int score1 = 86;
        // 定义静态变量score2
        static int score2 = 92; 
        // 定义静态方法sum,计算成绩总分,并返回总分
        public static int sum() { 
          HelloWorld hello=new HelloWorld();  
          hello.score1=99;
          return hello.score1 + score2;
        }
        public static void main(String[] args) {
            // 调用静态方法sum并接收返回值
            int allScore = sum();
            System.out.println("总分:" + allScore);
        }
    }


    查看全部
  • Static Variables

    The static keyword is used to create variables that will exist independently of any instances created for the class. Only one copy of the static variable exists regardless of the number of instances of the class.

    Static variables are also known as class variables. Local variables cannot be declared static.

    鉴于他作用的特殊性更推荐用类名访问

    静态成员属于整个类,当系统第一次使用该类时,就会为其分配内存空间直到该类被卸载才会进行资源回收!

    查看全部
  • Method Overloading

    When a class has two or more methods by the same name but different parameters, it is known as method overloading. It is different from overriding. In overriding, a method has the same method name, type, number of parameters, etc.


    查看全部

举报

0/150
提交
取消
课程须知
本课程是Java开发的基础,需要大家:掌握 Java 基本语法的使用。如果您是新手,建议先移步 《Java入门第一季》https://www.imooc.com/learn/85
老师告诉你能学到什么?
• 掌握 Java 编程思路 • 熟练运用面向对象程序设计思想
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!