Name: class Refint { int n; } class Driver ( static void g (RefInt r) { r.nr.n+ 1; r new Ref Int (); r. n = 0; } public static void main (String[] args) { Ref Ints new Ref Int (); s. n = 10; g (s); System.out.println (s.n); } } What is printed when this program is executed? A: 0 B: 10 C: 1 D: 2 E: 11
Name: class Refint { int n; } class Driver ( static void g (RefInt r) { r.nr.n+ 1; r new Ref Int (); r. n = 0; } public static void main (String[] args) { Ref Ints new Ref Int (); s. n = 10; g (s); System.out.println (s.n); } } What is printed when this program is executed? A: 0 B: 10 C: 1 D: 2 E: 11
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Scala programming
![### Programming Practice Problems
**Serial Number: 500**
---
#### Question 14
Consider the following Java code:
```java
class RefInt {
int n;
}
class Driver {
static void g (RefInt r) {
r.n = r.n + 1;
r = new RefInt();
r.n = 0;
}
public static void main (String[] args) {
RefInt s = new RefInt();
s.n = 10;
g(s);
System.out.println(s.n);
}
}
```
**What is printed when this program is executed?**
A: 0
B: 10
C: 1
D: 2
E: 11
<br><br>
#### Question 15
Consider the following Scala code:
```scala
var x = 10
val q = { x = x * 2; () => { x = x * 3; println (x) } }
var x = 11
```
**What will be printed when `q()` is executed twice?**
A: Prints 60 and 180 in that order.
B: Prints 66 and 198 in that order.
C: Prints 33 and 99 in that order.
D: Prints 60 and 360 in that order.
E: Prints 60 and 180 in that order.
<br><br>
#### Question 16
Consider the following C program:
```c
#include <stdlib.h>
#include <stdio.h>
int *f (int x) {
int y;
int *p = &y;
}
```](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F57e74000-fbe3-481d-ab8d-800d62a3b02c%2F57da977a-486c-442c-94f1-0b19918e9f1d%2Fvtq1lyg_processed.jpeg&w=3840&q=75)
Transcribed Image Text:### Programming Practice Problems
**Serial Number: 500**
---
#### Question 14
Consider the following Java code:
```java
class RefInt {
int n;
}
class Driver {
static void g (RefInt r) {
r.n = r.n + 1;
r = new RefInt();
r.n = 0;
}
public static void main (String[] args) {
RefInt s = new RefInt();
s.n = 10;
g(s);
System.out.println(s.n);
}
}
```
**What is printed when this program is executed?**
A: 0
B: 10
C: 1
D: 2
E: 11
<br><br>
#### Question 15
Consider the following Scala code:
```scala
var x = 10
val q = { x = x * 2; () => { x = x * 3; println (x) } }
var x = 11
```
**What will be printed when `q()` is executed twice?**
A: Prints 60 and 180 in that order.
B: Prints 66 and 198 in that order.
C: Prints 33 and 99 in that order.
D: Prints 60 and 360 in that order.
E: Prints 60 and 180 in that order.
<br><br>
#### Question 16
Consider the following C program:
```c
#include <stdlib.h>
#include <stdio.h>
int *f (int x) {
int y;
int *p = &y;
}
```
![---
## Computer Science Exam Questions
**Serial Number**: 500
### C Programming
```c
*p - x * 2;
return p;
}
int main (void) {
int *q = f (10);
printf ("result = %d\n", *q);
return 0;
}
```
#### Question: Which one of the following statements is true about the C code?
A: q is a dangling pointer.
B: p is a dangling pointer.
C: The assignment to *p is unsafe.
D: The variable y is moved to the heap at runtime.
E: q is not a dangling pointer.
### Java Programming
#### Question 17: Consider the following code in Java:
```java
class Driver {
static void g (int m) {
m = m + 1;
m = 0;
}
public static void main (String[] args) {
int n = 10;
g(n);
System.out.println (n);
}
}
```
#### Question: What is printed when this program is executed?
A: 11
B: 2
C: 1
D: 0
E: 10
### Scala Programming
#### Question 18: Consider the following Scala code:
```scala
val q = { var y:Int = 0; (x:Int) => { y = y + x; y } }
```
#### Question: What will happen when q(10) and then q(20) are executed?
A: Returns 0 and 0 in that order.
B: Returns 10 and 20 in that order.
C: Returns 0 and 30 in that order.
---](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F57e74000-fbe3-481d-ab8d-800d62a3b02c%2F57da977a-486c-442c-94f1-0b19918e9f1d%2Ft6l98rw_processed.jpeg&w=3840&q=75)
Transcribed Image Text:---
## Computer Science Exam Questions
**Serial Number**: 500
### C Programming
```c
*p - x * 2;
return p;
}
int main (void) {
int *q = f (10);
printf ("result = %d\n", *q);
return 0;
}
```
#### Question: Which one of the following statements is true about the C code?
A: q is a dangling pointer.
B: p is a dangling pointer.
C: The assignment to *p is unsafe.
D: The variable y is moved to the heap at runtime.
E: q is not a dangling pointer.
### Java Programming
#### Question 17: Consider the following code in Java:
```java
class Driver {
static void g (int m) {
m = m + 1;
m = 0;
}
public static void main (String[] args) {
int n = 10;
g(n);
System.out.println (n);
}
}
```
#### Question: What is printed when this program is executed?
A: 11
B: 2
C: 1
D: 0
E: 10
### Scala Programming
#### Question 18: Consider the following Scala code:
```scala
val q = { var y:Int = 0; (x:Int) => { y = y + x; y } }
```
#### Question: What will happen when q(10) and then q(20) are executed?
A: Returns 0 and 0 in that order.
B: Returns 10 and 20 in that order.
C: Returns 0 and 30 in that order.
---
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education