Exam Flashcards

1
Q

Switch

A

A switch works with the byte , short , char , and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character , Byte , Short , and Integer (discussed in Numbers and Strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Inner class

A
static nested class can access 
static member of enclosing class

member inner class can access static member of enclosing class

member inner class can access instance members of the enclosing class

local class can access instance members from within an instance method

anonymous class can access instance members from within an instance method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Short

A

you can assign any int literal that falls in the range of short (-32768 to 32767) to a short variable.

boolean variable cannot be cast to any other data type and vice versa

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

overriding

A

Overriding and Access-Modifiers : The access modifier for an overriding method can allow more, but not less, access than the overridden method.

Final methods can not
be overridden :

Static methods can not be overridden

Private methods can not be overridden

The overriding method must have same return type (or subtype)

Overriding and constructor : We can not override constructor as parent and child class can never have constructor with same name

If the super-class overridden method does not throw an exception, subclass overriding method can only throws the unchecked exception, throwing checked exception will lead to compile-time error.

Rule#2 : If the super-class overridden method does throws an exception, subclass overriding method can only throw same, subclass exception. .Also there is no issue if subclass overridden method is not throwing any exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Overloading

A

methods must have same name and different signature.

return type can or can not be be same, but we must have to change the parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Enum and static

A

Only top level types and static nested classes can define static members other than static constant. Emum are implicitly static

Static method can not be overridden

Anonymous class can not be abstract or final since it has not class definition

Only static nested class can include static method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

local variable type inference

A
Not permitted in class fields
Not permitted for uninitialized local variables
Not allowed as parameter for any methods
Not permitted in method return type
Not permitted with variable initialized with ‘NULL'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

@SafeVarargs Annotation

A
Final methods
Static methods
Constructors
From Java 9, it can also be use
Private Instance Method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

nested inner class and nested static inner class

A
To create an instance of nested inner static class
OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();
To create an instance of nested inner class
OuterClass outerObject = new OuterClass()
OuterClass.InnerClass innerObject = outerObject.new InnerClass();

local inner class instance is tied to and can access the final local variables of its containing method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly