100% complete solutions A+ rated
b) is correct.
1. Given:
¤Employee a1 and a2 reference variables are stored in stack memory.
public class Em-
¤Member variable id is stored in the heap memory.
ployee{
¤Static variable company Name is stored in class memory.
private static int
company Name; public class Employee{
private int id; private static int company Name;
public A(int private int id;
anId){ public A(int and){
id=anId; id=anId;
} }
public static void public static void main(String[] args){
main(String[] Employee a1 = new Employee(1);
args){ Employee a2 = new Employee(2);
Employee a1 }}
= new Employ-
ee(1); Note:
Employee a2
= new Employ- Stack Memory stores the reference variables to objects and method calls e.g. 'a1'
ee(2); and 'a2'.
}}
This can cause a StackOverflowError where the references collide with methods
What is the re- stored on the stack.
sult? (Choose all
that apply) Heap Memory is used to store objects and member variables
a) e.g.
new Employee(1);
Employee a1 and
a2 refs are stored new Employee(2);
in heap memory
,3 - Java OCA 8 – Assignments questions with
100% complete solutions A+ rated
Member variable Heap memory can cause an OutOfMemoryError.
,3 - Java OCA 8 – Assignments questions with
100% complete solutions A+ rated
id is stored in the
Class Memory stores static:
stack memory
static variable
• Variables
companyName is
• Methods
stored in class
• Method blocks
memory
Declaring static variables makes the program more memory eflcient.
b)
Employee a1 and
a2 refs are stored
in stack memory
Member variable
id is stored in the
heap memory
static variable
companyName is
stored in class
memory
c)
Employee a1 and
a2 refs are stored
in stack memory
Member variable
id is stored in the
class memory
static variable
companyName is
stored in heap
memory
, 3 - Java OCA 8 – Assignments questions with
100% complete solutions A+ rated
d) none of the
above
2. Which of the b) is correct.
following are
true statements?- Declaring static variables makes the program more memory eflcient.
(Choose all that
Note:
apply)
Stack Memory stores the reference variables to objects and method calls e.g. 'a1'
a) Declaring
and 'a2'.
static variables
makes the pro-
Consider the following sample program:
gram less memo-
ry efficient 1: public class Employee{
b) Declaring 2: private static int companyName;
static variables 3: private int id;
makes the pro- 4: public A(int anId){
gram more mem- 5: id=anId;
ory efficient 6: }
c) Declaring static 7: public static void main(String[] args){
variables makes 8: Employee a1 = new Employee(1);
the program 9: Employee a2 = new Employee(2);
more easier to 10: }}
read
d) none of the On the line 8 and 9 of the main() method, local reference variables 'a1' and 'a2'
above are declared.
If there was an infinite recursive call to a method in the program, this could cause
a StackOverflowError where the references collide with methods stored on the
stack.