Methods and Strings Flashcards
methods declaration has two parts
method header, method body
method header defines …
name, parameters, return type
method body is the…
actual body of the method that defines its logic
final methods can be overridden ?
false
abstract must be?
must be overridden has an empty body in parent class but no in child classes
method overloading is
having more than one method with the same name but with different parameter types or different number of parameters
return type cannot be used to overload method ?
true
parameters in java are passed by value?
true
if the parameter is an object then what is passed? (value or reference)
it is the object reference is passed
this keyword references
to the object from which is called
main method
public static void main(String[] args)
why main method is public?
to be accessed from the outside
why static main method?
so no instantiation required
why string[] args ?
pass parameters to the program
when a object is eligible for garbage collection? it will be
deleted by garbage collector
when is an object eligible for garbage collection?
when the reference is null or
if the object reference is made to reference to another object
how to force a garbage collector to work
system.gc
strings is considered a
sequence of characters
strings are … (immutable- mutable)
immutable
what does strings are immutable mean?
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
to convert any object to string you should override
the method toString()
to compare strings we use
equals()
== operator can be used to compare strings
no , it compares addresses only
compare to returns what when it s1 = s2
0
substring method returns
substring starting position and ends at another position
indexof returns
finds a substring if exists and returns its positions (-1 if not found)