You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Java Core/Java Basics.md
+33-33Lines changed: 33 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -18,49 +18,49 @@ Java Basics
18
18
19
19
4.**State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.**
20
20
21
-
public
22
-
class -- accessible from anywhere. Can be subclassed by anyone (if not declared final)
23
-
method -- accessible from anywhere. Can be overriden in subclasses.
24
-
variable -- accessible from anywhere. Usually not a good practice except for the constants
25
-
inner class -- accessible from anywhere.
26
-
nested class-- accessible from anywhere.
27
-
private
28
-
class -- only for inner classes.
29
-
method -- accessible only from the class where it is declared. Cannot be overridden
30
-
variable -- accessible only from the class where it is declared
31
-
inner class -- same
32
-
nested class-- same
33
-
protected
34
-
class -- only for inner classes
35
-
method -- accessible from the same package or from any subclass
36
-
variable -- same
37
-
inner class -- same
38
-
nested class-- can be written but doesn't make sense (protected static!?)
39
-
default(no access modifier)
40
-
class -- only this package and subclasses in this package
41
-
method -- same
42
-
variable -- same
43
-
inner class -- same
44
-
nested class-- same
21
+
*public
22
+
class -- accessible from anywhere. Can be subclassed by anyone (if not declared final)
23
+
method -- accessible from anywhere. Can be overriden in subclasses.
24
+
variable -- accessible from anywhere. Usually not a good practice except for the constants
25
+
inner class -- accessible from anywhere.
26
+
nested class-- accessible from anywhere.
27
+
*private
28
+
class -- only for inner classes.
29
+
method -- accessible only from the class where it is declared. Cannot be overridden
30
+
variable -- accessible only from the class where it is declared
31
+
inner class -- same
32
+
nested class-- same
33
+
*protected
34
+
class -- only for inner classes
35
+
method -- accessible from the same package or from any subclass
36
+
variable -- same
37
+
inner class -- same
38
+
nested class-- can be written but doesn't make sense (protected static!?)
39
+
*default(no access modifier)
40
+
class -- only this package and subclasses in this package
41
+
method -- same
42
+
variable -- same
43
+
inner class -- same
44
+
nested class-- same
45
45
46
46
5.**What is an abstract class?**
47
47
48
48
An abstract class is a java class that has one or more abstract methods (no body). Abstract classes cannot be instantiated. Abstract class defines an interface that has to be implemented by all its subclasses.
49
49
50
50
6.**What is static in java?**
51
51
52
-
static is Java Language keyword.
53
-
a) When used with a method defines a method of a class.
54
-
b) When used with a field defines a class field.
55
-
c) When used on an nested class declaration defines a static nested class.
56
-
d) Also can be used for static initialization block.
52
+
static is Java Language keyword.
53
+
a) When used with a method defines a method of a class.
54
+
b) When used with a field defines a class field.
55
+
c) When used on an nested class declaration defines a static nested class.
56
+
d) Also can be used for static initialization block.
57
57
e) Can be used as a static initialization block
58
58
59
59
7.**What is final?**
60
60
61
-
final is Java Language keyword.
62
-
a) When used with a method protects it from being overridden in subclasses. Done for security and/or performance reasons.
63
-
b) When used with a field means that the value stored in the field cannon be changed after initialization. Not to be confused with immutability of the object.
61
+
final is Java Language keyword.
62
+
a) When used with a method protects it from being overridden in subclasses. Done for security and/or performance reasons.
63
+
b) When used with a field means that the value stored in the field cannon be changed after initialization. Not to be confused with immutability of the object.
64
64
c) When used with a class declaration protects it from being subclassed. Done for security and/or performance reasons. Also for immutability. Many of Java core classes are final (e.g. String)
65
65
66
66
8.**How can one prove that the array is not null but empty using one line of code?**
0 commit comments