• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Data hiding concept error

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

I have a question:

public class Name{
public static void getMyName(){ }
}

public class MyName extends name{
private static void getMyName(){ }
}

I know if I remove the "private static" words form class MyName's method, it will work. Here the data hiding concept works perfectly.
It gives you aceessibilty error if I keep those words their. Here why the data hiding is not working?
Why the data hiding concept not working for these static methods?
 
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you made those methods static? A get or set method usually needs access to an instance field and cannot be made static. And get methods return the value sought, so should not have a void return type.

If those methods are static, then your question is meaningless.
 
Malhar Me
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response..
I am just giveing a name to method for just identification, whatever the name the method have it doent matter.
The basic question is about data hiding concept.

Static method are not overridden, then why it shows me error if I use same method with diffrent accessspecifier?
 
Campbell Ritchie
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only thing I could find in the Java™ Language Specification which might help suggests you have two methods with override-equivalent signatures.

Anybody else know any better, please?
 
Campbell Ritchie
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult a question for "beginning Java". Moving.ah
 
Ranch Hand
Posts: 99
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone have any idea about above mention problem by Malhar Me.

Why compiler is throwing an error- "cannot override method" when we try to redefine static method in sub-class with weaker access privileges, even though static method can not be overridden. Is this some bug in java.

Thanks,
Anuj
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic