OCP open points

some open points

some open points


Fichier Détails

Cartes-fiches 90
Langue Deutsch
Catégorie Informatique
Niveau Autres
Crée / Actualisé 09.01.2020 / 10.01.2020
Lien de web
https://card2brain.ch/box/20200109_ocp_open_points
Intégrer
<iframe src="https://card2brain.ch/box/20200109_ocp_open_points/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>

Was passiert wenn eine Klasse von zwei interfaces eine Methode mit derselben Signatur erbt, in einem interface ist sie allerdings default (also schon implementiert)?

Die Klasse muss sie dennoch selbst implementieren (gleich wie wenn kein default oder beide default)

Zu welcher Kategorie von Klassen gehört ArrayList?

Zu den collections

Was ist der Unterschied zwischen ArrayList.size() und ArrayList.capacity()?

size its die Anzahl elemente in der ArrayList und capacity die Länge des Arrays

Ist eine Map auch eine Collection?

Nein

Was ist jdeps?

Der Java class dependency analyzer

Kann eine überschreibende Methode die Methode final machen?

Ja


What will the following code print when run?
class A {
}

class AA extends A { 
}


public class TestClass {
    public static void main(String[] args) throws Exception {
        A a = new A();
        AA aa = new AA();
        a = aa;
        System.out.println("a = "+a.getClass());
        System.out.println("aa = "+aa.getClass());
    }
}

a = class AA
aa = class AA

-> nimmt die Methode des Objektes das referenzier twird -> a und aa referenzieren beide dasselbe Objekt!

What will be the result of attempting to compile and run the following program?


public class TestClass{
   public static void main(String args[ ] ){
      A o1 = new C( );
      B o2 = (B) o1;
      System.out.println(o1.m1( ) );
      System.out.println(o2.i );
   }
}
class A { int i = 10;  int m1( ) { return i; } }
class B extends A { int i = 20;  int m1() { return i; } }
class C extends B { int i = 30;  int m1() { return i; } }

30,20 :

Which variable (or static method) will be used depends on the class that the variable is declared of.
Which instance method will be used depends on the actual class of the object that is referenced by the variable.     


Consider the following code:
class A{
   A() {  print();   }
   void print() { System.out.println("A"); }
}
class B extends A{
   int i =   4;
   public static void main(String[] args){
      A a = new B();
      a.print();
   }
   void print() { System.out.println(i); }
}
What will be the output when class B is run ?

0, 4

        Note that method print() is overridden in class B. Due to polymorphism, the method to be executed is selected depending on the class of the actual object.
Here, when an object of class B is created, first B's default constructor (which is not visible in the code but is automatically provided by the compiler because B does not define any constructor explicitly) is called. The first line of this constructor is a call to super(), which invokes A's constructor. A's constructor in turn calls print(). Now, print is a non-private instance method and is therefore polymorphic, which means, the selection of the method to be executed depends on the class of actual object on which it is invoked. Here, since the class of actual object is B, B's print is selected instead of A's print. At this point of time, variable i has not been initialized (because we are still in the middle of initializing A), so its default value i.e. 0 is printed.     

validateEmployee(e, e->e.age<10000)

wäre das ok?

Nein:

Remember that the parameter list part of a lambda expression declares new variables that are used in the body part of that lambda expression. However, a lambda expression does not create a new scope for variables. Therefore, you cannot reuse the local variable names that have already been used in the enclosing method to declare the variables in you lambda expression. It would be like declaring the same variable twice.
Here, the main method has already declared a variable named e. Therefore, the parameter list part of the lambda expression must not declare another variable with the same name. You need to use another name. For example, if you change //3 to the following, it will wor