• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

nPrint method in JAVA

 
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I am so confused with nPrint method in java.Please help me.


Thanks in advance...
 
Marshal
Posts: 27368
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But nPrint isn't a method of any of the classes in the standard Java API. So it must be a method of some other class. Which means we know nothing except that you're asking about a method named "nPrint". Please read this: TellTheDetails and then post some information about just what is confusing you.
 
Rd Dari
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing this question but I do not understand this.....

What is k after the following block executed?
{
int k = 2;
nPrint("A message", k);
}
 
Rd Dari
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is k after the following block executed?
{
int k = 2;
nPrint("A message", k);
}

The output of this:
k is not defined outside the block.

So I am confusing.......
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code. It will highlight your code and make it easier to read. It probably will also increase the number of people helping you.

Try to TellTheDetails in advance. That way we don't have to ask you for more information and nobody is wasting time.

The keyword is scope. If you declare a variable then it has a scope. It is visible (in scope) between the two brackets it is declared in. After that it's no longer in scope and can't be accessed. So after your method has run the variable k is out of scope and can't be reached.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic