ocp 2


Kartei Details

Karten 141
Sprache Deutsch
Kategorie Informatik
Stufe Andere
Erstellt / Aktualisiert 22.09.2020 / 06.12.2020
Weblink
https://card2brain.ch/box/20200922_java_2_2
Einbinden
<iframe src="https://card2brain.ch/box/20200922_java_2_2/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>

What must be defined if we want to use @Repeatable?

a containing type value, f.e.:
public @interface Risks {
  Risk[] value();
}

What are the rules for the @Repeatable annotation?

  • repeatable annotation must be declared with @Repeatable and contain a value that refers to the containing type annotation
  • The containing type annotation must include an element named value() which is a primitive array of the repeatable annotation type

What are common values for @SupressWarnings?

"deprecation"
"unchecked"

What information does @SafeVarargs provide?

indicates that a method does not perform any potential unsafe operations on its varargs parameter

Where can @SafeVarargs be applied?

only to constructos or methods that cannot be overwritten and contain a varargsparameter

How to get an array of all the values of an enum?

with the values() method: 
SomeEnum.values()

How to get a enum value of a string? What happens if it doesnt exist?

SomeEnumValue.valueOf("thename");

throws exception

Can a enum be extended?

No

Whats the problem hre?
switch(summer) {
  case Season.FALL;
     break;
  case 0:
   break;
}

Season.Fall doesnt work, should be FALL
Enum values cannot be compared with int

How to create a function with different behaviour for each enum?

within the enum class: public abstract...
-> has to be implemented by all enum-types

What are the properties of inner classes?

  • can be declared public, protected, package-private or private
  • can extend any class or implement interfaces
  • can be marked abstract or final
  • cannot declare static fields or methods except for static final fields
  • can access members of the outer class including private members

What are the properties of static nested classes?

like a top-level-class except for:

  • the nesting creates a namespace because the enclosing class name must be used to refer to it
  • can be made private or use one of the other access modifiers to encapsulate it
  • enclosing class can refer to the fields and methods of the static nested class

Poperties of local classes?

  • do not have an access modifier
  • cannot be declared static and cannot declare static fields or methods except for static final fields
  • have access to all fields and methods of the enclosing class
  • can access local variables if the variables are final or effectively final

What are rules for default interface methods?

  • method may be declared only within an interface
  • methoid must be marked with default keyword and include a method body
  • method is assumed to be public
  • method cannot be marked abstract, final or static
  • method may be overridden by a class that implements the interface
  • if a class inherits two or more default mehtods with the same method signature, then the class must override the method

How to call the getSpeed implementation of Walk here?
public class Cat implements Walk, Run {
  public int getSpeed() { return 1; }
  public int getWalkSpeed() {
     return ????; // Todo
  }
  public static void main(String[] args) {
    System.out.println(new Cat().getWalkSpeed());
  }
}

walk.super.getSpeed();

What are rules for static interface method definitions?

  • method must be marked with the static keyword and include a method body
  • method without an access modifier is assumed to be public
  • method cannot be marked abstract or final
  • method is not inherited and cannot be accessed in a class implementing the interface without a reference to the interface name

What are rules for private interface method definitions?

  • private interface method must be marked with the private modifier and include a method body
  • private interface method may be called only by default and private (non static methods within the interface definition

  • What are rules for private static interface method definitions?

  • a private static method must be marked with private and static modifiers and include a method body
  • a private static interface method may be called only by other methods without the interface definition

What ist the SAM rule?

single abstract method 

What is the exception of the SAM rule?

the methods inherited by Object

Whats the rule with var in lambda expresions?

you can use var inside a lambda parameter list but if a var is used for one of the types in the parameter list then it must be used fo all parameters in the list