OOP Theory 3 Part 2
OOP Theory 3 Part 2
OOP Theory 3 Part 2
Ex.2) When you run a Java application by typing java someClass what is
the first method that starts?
a. The main() method of someClass. b. The run() method someClass.
c. The someClass method. d. The applet method.
Ex.6) Which of the following invokes the method length() of the object str
and stores the result in val?
a. val = str.length() b. val = length.str()
c. val = length().str d. val = length( str );
How many objects (total) are created? After the last statement has
executed, how many objects are now accessible (don't count garbage)?
a. This section of code is incorrect.
b. created: 5 now accessible: 5
c. created: 1 now accessible: 1
d. created: 5 now accessible: 1
executed, how many objects are now accessible (don't count garbage)?
a. This section of code is incorrect.
b. created: 5 now accessible: 5
c. created: 1 now accessible: 1
d. created: 5 now accessible: 1
Ex.18) Objects of type String are immutable which means that once you
create them you cannot change them.
Create a class called MyPoint which is also immutable and which has the
following instance variables and methods:
- x coordinate
- y coordinate
- print method to output the point
String str=“Yes”;
Yes
str
Yes
str=“No”; str
No
You couldn’t do this with a string object. There is also another useful
class called StrignTokenizer which can be used to break strings into
smaller strings:
BufferedReader br=new BufferedReader (new
FileReader("test.txt"));
String line=br.readLine();
StringTokenizer st=new StringTokenizer(line);
This class can be useful when retrieving data from delimited text files. It
relieves the programmer from having to do the extraction process
manually. For more information on the JDK documentation.