NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#
41. What is the output of the following program?

import java.util.Date;

public class Test {
public static void main(String[] args) {
Date date = new Date(1234567);
m1(date);
System.out.print(date.getTime() + " ");

m2(date);
System.out.println(date.getTime());
}

public static void m1(Date date) {
date = new Date(7654321);
}

public static void m2(Date date) {
date.setTime(7654321);
}
}
a. 1234567 1234567
b. 1234567 7654321
c. 7654321 1234567
d. 7654321 7654321
Key:b

#
Section 9.11 Array of Objects
42. Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?
a. x contains an array of ten int values.
b. x contains an array of ten objects of the Circle type.
c. x contains a reference to an array and each element in the array can hold a reference to a Circle object.
d. x contains a reference to an array and each element in the array can hold a Circle object.
Key:c

#
43. Assume java.util.Date[] dates = new java.util.Date[10], which of the following statements are true?
a. dates is null.
b. dates[0] is null.
c. dates = new java.util.Date[5] is fine, which assigns a new array to dates.
d. dates = new Date() is fine, which creates a new Date object and assigns to dates.
Key:bc

#
Section 9.12 Immutable Objects and Classes
44. Which of the following statements are true about an immutable object?
a. The contents of an immutable object cannot be modified.
b. All properties of an immutable object must be private.
c. All properties of an immutable object must be of primitive types.
d. An object type property in an immutable object must also be immutable.
e. An immutable object contains no mutator methods.
Key:abde

#
Section 9.13 Scope of Variables
45. What is the output for the first statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;

public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}

k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
a. i + j is 5
b. i + j is 6
c. i + j is 22
d. i + j is 23
Key:d The first + operator in the expression "i + j is " + i + j is evaluated.

#
46. What is the output for the second statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;

public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}

k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
a. k is 0
b. k is 1
c. k is 2
d. k is 3
Key:c When computing k = i + j, i is 2 and j is 0.

#
47. What is the output for the third statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;

public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}

k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
a. j is 0
b. j is 1
c. j is 2
d. j is 3
Key:a

#
48. You can declare two variables with the same name in __________.
a. a method one as a formal parameter and the other as a local variable
b. a block
c. two nested blocks in a method (two nested blocks means one being inside the other)
d. different methods in a class
Key:d

#
Section 9.14 The this Keyword
49. Analyze the following code:

class Circle {
private double radius;

public Circle(double radius) {
radius = radius;
}
}
a. The program has a compile error because it does not have a main method.
b. The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.
c. The program has a compile error because you cannot assign radius to radius.
d. The program does not compile because Circle does not have a default constructor.
Key:b You have replace radius = radius by this.radius = radius

#
50. Analyze the following code:

class Test {
private double i;

public Test(double i) {
this.t();
this.i = i;
}

public Test() {
System.out.println("Default constructor");
this(1);
}

public void t() {
System.out.println("Invoking t");
}
}
a. this.t() may be replaced by t().
b. this.i may be replaced by i.
c. this(1) must be called before System.out.println("Default constructor").
d. this(1) must be replaced by this(1.0).
Key:ac

#
51. Which of the following can be placed in the blank line in the following code?
public class Test {
private int id;

public void m1() {
_____.id = 45;
}
}

a. this
b. Test
Key:a
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.