Methods and Strings Flashcards

1
Q

methods declaration has two parts

A

method header, method body

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

method header defines …

A

name, parameters, return type

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

method body is the…

A

actual body of the method that defines its logic

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

final methods can be overridden ?

A

false

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

abstract must be?

A

must be overridden has an empty body in parent class but no in child classes

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

method overloading is

A

having more than one method with the same name but with different parameter types or different number of parameters

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

return type cannot be used to overload method ?

A

true

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

parameters in java are passed by value?

A

true

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

if the parameter is an object then what is passed? (value or reference)

A

it is the object reference is passed

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

this keyword references

A

to the object from which is called

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

main method

A

public static void main(String[] args)

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

why main method is public?

A

to be accessed from the outside

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

why static main method?

A

so no instantiation required

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

why string[] args ?

A

pass parameters to the program

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

when a object is eligible for garbage collection? it will be

A

deleted by garbage collector

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

when is an object eligible for garbage collection?

A

when the reference is null or

if the object reference is made to reference to another object

17
Q

how to force a garbage collector to work

A

system.gc

18
Q

strings is considered a

A

sequence of characters

19
Q

strings are … (immutable- mutable)

A

immutable

20
Q

what does strings are immutable mean?

A

means their value cant be changed , they simply reference to another place in memory and add the new value to it they dont change directly

21
Q

to convert any object to string you should override

A

the method toString()

22
Q

to compare strings we use

A

equals()

23
Q

== operator can be used to compare strings

A

no , it compares addresses only

24
Q

compare to returns what when it s1 = s2

A

0

25
Q

substring method returns

A

substring starting position and ends at another position

26
Q

indexof returns

A

finds a substring if exists and returns its positions (-1 if not found)