• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Miscellaneous Doubts

 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
QUESTION 1:


Which are true? (Choose all that apply.)
A. The output could contain 30
B. The output could contain @bf73fa
C. The output could contain DIAMONDS
D. Compilation fails due to an error on line 6
E. Compilation fails due to an error on line 7
F. Compilation fails due to an error on line 8

Ans: A and B
But on line 13 points is accessed wch is private then

shudnt the code fail to compile?
 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
QUESTION2:




What is the result?
A. 5 7
B. 5 8
C. 8 7
D. 8 8
E. Compilation fails
F. An exception is thrown at runtime

Ans: E

The parameter declared on line 9 is valid (although ugly), but the variable
name ouch cannot be declared again on line 11 in the same scope as the declaration on
line 9.

but isnt ouch declared inside for inside another scope?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all QuoteYourSources.

About question 1. The main method is in the same class thus has access.
About question 2. No that is not true. Because the method parameter ouch is still visible in the for loop and cannot be hidden.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please post individual questions in their own topics with appropriate subjects.
 
sumit kothalikar
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 1:here we are accessing the private variable of the class from te class itself thus it has access

as explained bu Wouter Oet
About question 1. The main method is in the same class thus has access.
 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou All...

The question are from(K&B)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic