-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
daily shareDaily Share SummaryDaily Share SummarydocumentationImprovements or additions to documentationImprovements or additions to documentationquestionFurther information is requestedFurther information is requested
Description
2019-11-18~2019-11-23 周分享总结
分享人:何芷靓| 分享日期:2019-11-18
题目:
class Egg{
protected class Yolk{
public Yolk(){
System.out,println("Egg.Yolk");
}
}
private Yolk y;
public Egg(){
System.out.println("New Egg()");
y=new Yolk();
}
}
class BigEgg extends Egg{
public class Yolk{
public Yolk(){
System.out.println("BigEgg.Yolk()");
}
}
public static void main(String[]args){
new BigEgg();
}
}public class A{
public void A(){System.out.println("A");}
public void AC(){A();}
}
public class B extends A{
public void A(){System.out.println("B");}
public void D(){super.AC();}
public static void main(String args[]){
B b=new B();
b.D();
}
}回答:
1.New Egg()
Egg.Yolk()
2.B解答:
1.初始化子类之前需要先进行父类的初始化,所以会调用父类的构造方法。先输出New Egg() 然后又new了一个内部类对象 所以调用内部类Yolk的构造方法 输出Egg.Yolk。
2.主方法里调用了对象b对象的D方法,D方法又调用了父类的AC方法。父类的AC方法又调用了A方法,但是此时子类覆盖了父类的A方法,默认调用了子类重写的A方法,所以输出B
分享人:孙鹏翔| 分享日期:2019-11-19
关于内部类的两篇博客
分享人:杨兴旺| 分享日期:2019-11-20
问题:
public class Test2{
public static void main(String args[]){
Parrent p=new Parrent();
Parrent c=new Child();
System.out.println(p.getName());
System.out.println(c.getName());
}
}
class Parrent{
public static String getName(){
return "Parrent";
}
}
class Child extends Parrent{
public static String getName(){
return "child";
}
}答案:
Parrent
Parrent解答:1.在java中静态方法可以被继承,但是不能被重写。
2.父类引用指向子类对象时,只会调用父类的静态方法,不具有多态性。(输出两个Parrent的原因)
分享人:宋丽| 分享日期:2019-11-21
public class TestSync2 implements Runnable{
int b=100;
synchronized void m1()throws InterruptedException{
b=1000;
Thread.sleep(500); //6
System.out.println("b="+b);
}
synchronized void m2() throws InterruptedException{
Thread.sleep(250); //5
b=2000;
}
public static void main(String args[])throws InterruptedException{
TestSync2 tt=new TestSync2();
Thread t=new Thread(tt); //1
t.start(); //2
tt.m2();
System.out.println("main thread b="+tt.b);//4
}
@Override
public void run()
{
try{
m1();
}
catch(InterruptedException e){
e.printStackTrace();
}
}分享人:韩思玥| 分享日期:2019-11-22
关于怎样上传图片到七牛云并返回图片的url
分享人:王增益| 分享日期:2019-11-23
问题:
interface(接口)里面可以有方法的实现吗?
回答:default和static方法可以在接口里实现。
注意事项:
1.接口的默认方法,可以直接使用实现类的对象进行调用,也可以在实现类中对其进行覆盖重写。
2.接口中静态方法和类中静态方法一样,只能通过接口.静态方法名的方式调用
直接整活(放代码):
public interface Ceshi {
public default void s1(){
System.out.println("默认方法");
}
public static void s2(){
System.out.println("静态方法");
}
}public class Impl implements Ceshi {
}
public class Main {
public static void main(String []args) {
Impl impl = new Impl();
impl.s1();
Ceshi.s2();
}
}结果:
默认方法
静态方法
Metadata
Metadata
Assignees
Labels
daily shareDaily Share SummaryDaily Share SummarydocumentationImprovements or additions to documentationImprovements or additions to documentationquestionFurther information is requestedFurther information is requested