What happens when a member of the class has no access modifier?
It’s default
What is the difference between protected and default access?
Protected members are accessible in the subclass, whereas the default members are not
Polymorphism can be of two forms: dynamic and static.
What is the difference between them?
Dynamic polimorphism: When different forms of a single entity are resolved during runtime
static pol.: When forms of a single entity are resolved at compile time (ex. function overloading, abstract methods)
What are the key points for overriding a method?
What is the signature of the method equals?
public boolean equals(Object obj)
What are the key points of making a class immutable?
What is encapsulation
combining data and the functions operating it as a single unit
What are the four flavors of nested classes in java?
Where can you defined a static nested class(or interface)?
you can define a class ( or interface) as a static member inside another class (or interface)
the combinations:
class Outer { // an outer class has a static nested class
static class Inner {}
}interface Outer { // an outer interface has a static nested class static class Inner {}
}
class Outer { // an outer class has a static nested interface static interface Inner {}
}interface Outer { // an outer interface has a static nested interface static interface Inner {}
}
Where can you define a inner class?
You can define a class (or interface) as a non static member inside another class
class Outer { // an outer class has an inner class
class Inner {}
}
class Outer { // an outer class has an inner interface
interface Inner {}
}How to instantiate a static nested class?
OuterClassName.NestedClassName staticNested = new OuterClassName.NestedClassName()
how to instantiate a inner class?
center = this.new Point(x, y);
this.new InnerClass();
Which three kinds of methods can interface have?
Abstract, default and static methods
Whats the difference between abstract classes and interfaces?
Fields: abstract class can have static and non-static fields. Interfaces cannot cannot have non-static fields
constants: abstract class can have both static and non static constants. Interfaces can only have static constants
constructor: you can define a constructor in an abstract class. Cannot defined/declare constructor in an interface
acess specifiers: you can have private and protected/public members in an abstract class. cannot have any private or protected members in an interface
What are default methods?
default methods are instance methods. Inside the default method, this keyword refers to the declaring interface. default methods can call methods from the interface they are enclosed in.
What is a functional interface?
A functional interface specifies only one abstract method. Sometimes they are known as SAM (Single abstract method) type or interface.
However, it may have any number of default or static methods defined in it
How is the @FunctionalInterface used?
To affirm that an interface is a functional interface. The compiler will assure that or else it will throw compile error
What is the lambda syntax?
LambdaParameters -> LambdaBody
LambdaParameters: Are parameters to the lambda function are passed within opening parenthesis. When more than one parameter is passed, they are separeted by commas.
LambdaBody: can be an expression or block. The body could consist of single statement(in this case no explicit curly braces definining a block are required. Such a lambda body is known as “expression lambda”. If there are many statements in a lambda body, they need to be in a block of code.
interface LambdaFunction {
void call();
}public static void main(String []args) {
LambdaFunction lambdaFunction = () -> System.out.println(“Hello world”);
lambdaFunction.call();
}
How does the lambda expression relate to the function interface LambdaFunction?
It is through the single abstract method inside the LambdaFunction interface: void call(). The signature of this abstract method and the lambda expression must match.
What is effectively final variables in lambdas?
Lambda functions can refer to local variables from the enclosing scope. The variables need to be explicitly declared final or that variable will be treated as effectively final final. Which meeans that the compiler treats the variable as final variable and will issue an error if we try to modify it within the lambda function or in the rest of the function
What happens if a lambda expression throws an exception?
If it is a checked exception, then the method in the functional interface should declare that; otherwide it will result in a compiler error
Are inner classes allowed to contain static methods or static variables?
NO
Do abstract enum methods require each enum type to implement the method?
Yes
What is a member inner class?
Is a class that is defined at the same level as the instance variables