Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Static reference

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I found the following in valiveru's mock exam.

a static reference cannot be made through non static method or code block.

Is this true or false?

I answered as False because we can access static variables from non static methods. But the answer given is True.

Anybody please clarify how this is true.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that the question as it was asked? If not, can you post the question as-is?
 
Roja Rani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The exact question is as follows:

Question 43.

Which of the follwing is true about static modifier.

A.static can be applied to : instance variables, methods,
code Segments and classes.

B.a static method cannot be overridden.

C.inner classes can be both static & private.

D.a static reference cannot be made through non static
method or code block.

E.abstract & static both can be applied together to a
method.

Ans: B,C,D.

My doubt is regarding 'D'. How could it be true? Please clarify.
 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
It seems that D is wrong,
may be some mistake in the mock
[ October 08, 2005: Message edited by: Sandeep Chhabra ]
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Even i dont have a good reason...for the option

probably there is some typo...error..


 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Roja Rani:

a static reference cannot be made through non static method or code block.



He says "through" if he had used "in" instead, the answer would definitely be false. What does he mean by reference through?
Maybe he meant "static references cannot be created in non static methods/code blocks"
In any case It is a poorly framed question (according to me)
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi akshay...



static references cannot be created in non static methods/code blocks



I am not able to get this point ..can you elaborate it further..

Tx
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
As far as i think
a static reference cannot be made through non static method or code block
would mean that you cannot call a static method or variable from a non static method or code block

And I would answer this statement as False.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


As far as i think
a static reference cannot be made through non static method or code block
would mean that you cannot call a static method or variable from a non static method or code block



If that's what is meant here, then i agree that the statement is false..


 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
why A is false ..is it that classes means all(inner classes,top level classes)....

if there was only innerclasses instead of classes then i think it is true ..
am i right friends ??

thanks
sri
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srikanth reddy:
hi
why A is false ..is it that classes means all(inner classes,top level classes)....

if there was only innerclasses instead of classes then i think it is true ..
am i right friends ??

thanks
sri



HI Srikanth

A. static can be applied to : instance variables, methods,
code Segments and classes.



Do you think you can use static keyword with instance variables. And if Yes, will the variables anymore remain instance variables.
If you use static with any variable, in becomes class variable.
hence A is false.

Hope you got it
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic