Java内部类使用注意事项: 1. 非静态内部类成员可以访问外部类实例成员 (如注释1),但外部类访问非静态内部类的成员 必须创建非静态内部类对象来访问其成员,如注释2 public class Lab02 { private int ss=5; private class InnerClass{ private int demo=4; private void test() { //注释1:非静态内部类可以直接访问外部类变量 System.out.println("外部类成员变量ss的值--&…
题目: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Example: matrix = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15] ], k = 8, return 13. 分析:采用优先队列,自定义比较规则,使得最小元素排在队首. 代码:…
题目: You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u,v) which consists of one element from the first array and one element from the second array. Find the k pairs (u1,v1),(u2,v2) ...(uk,vk)…
下面default类就是默认修饰符的类 1.Java中调用类中属性或方法(不管是否静态属性或方法)都要在类的方法中调用,虽然这个太基础,但今天想在类中调用静态类的静态变量,不能调用: 2.Java调用内部类公共变量: public class A { public class AA { public int i = 0; } } public class B { public void method() { int i = new A().new AA().i; } } 3.一个.java文件内…
Sole purpose of using concurrency is to produce scalable and faster program. But always remember, speed comes after correctness. Your Java program must follow its invariant in all conditions, which it would, if executed in sequential manner. If you a…
继承.接口:Java子类中如果含有父类中不包含的变量与方法,子类对象向上转型时就是丢失这些变量和方法. interface SuperClass{ int i = 2; void f() ; } class SubClass implements SuperClass{ int i = 1 ; int j = 2 ; public void f(){ System.out.println("SubClass.f()"); } public void fun(){ System.out.…