473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

I need help on java modifiers, pls.

mayfjf
14
1. Hello, I wonder what are the differences between modifiers? Private, public, default, static...? I have reread and reread my java book, but I just can't understand. Thanks for any info...

May
Jan 30 '07 #1
11 1300
hirak1984
316 100+
look at this. or this
Jan 30 '07 #2
mayfjf
14
look at this. or this
Thanks... It really helps!

May
Jan 30 '07 #3
hirak1984
316 100+
there is a request please dont post more than one thread with same question.It
really makes people confused.
Best of luck.
Jan 30 '07 #4
mayfjf
14
there is a request please dont post more than one thread with same question.It
really makes people confused.
Best of luck.
Yeah, sorry for making anyone confused. I am really new to TSDN and I myself didn't know how did I post two threads with one subject. Maybe I have clicked the 'Submit reply ' button twice. Next time, i'd be very careful.

May
Feb 1 '07 #5
r035198x
13,262 8TB
Yeah, sorry for making anyone confused. I am really new to TSDN and I myself didn't know how did I post two threads with one subject. Maybe I have clicked the 'Submit reply ' button twice. Next time, i'd be very careful.

May
Yeah you probably hit the button twice.
Feb 1 '07 #6
dmjpro
2,476 2GB
1>Private is a modifier which can be used in class member
with in the the class scope u can use those members...

2>Public is a modifier whole packages can access those members

3>Default is a modifier which can be accessed through out the same package only

4>Static is modifier which is only accessed without using the class object reference.
the static can be further public private or default.
default means with out modifier specification it is default......

thankkksksssss............
Feb 3 '07 #7
r035198x
13,262 8TB
1>Private is a modifier which can be used in class member
with in the the class scope u can use those members...

2>Public is a modifier whole packages can access those members

3>Default is a modifier which can be accessed through out the same package only

4>Static is modifier which is only accessed without using the class object reference.
the static can be further public private or default.
default means with out modifier specification it is default......

thankkksksssss............
Default is not a Java modifier, the modifier is protected.
Static objects can be accessed using a class object reference.
Feb 3 '07 #8
dmjpro
2,476 2GB
in the same package the default access specifier and protected acts as same....
but in different package the protected can be accessed in subclasses but the default is not.
Feb 3 '07 #9
mayfjf
14
I have already tried some simple programs using static , and here is my sample codes, (these compile)...

Expand|Select|Wrap|Line Numbers
  1. //SAMPLE PROGRAM ON THE USE OF STATIC MODIFIER
  2.  
  3. package java_samples;
  4.  
  5. class samp1{
  6.  
  7.     public static void main(String args[]){
  8.         System.out.println(1+2+"3");
  9.         System.out.println("1"+ 2+1+2);
  10.         class1.member1();
  11.         class1.member2();
  12.         System.out.println(class1.part1); // part1 is static, it can be   accessed even without creating an object.
  13.     }
  14. }
  15.  
  16.  
Expand|Select|Wrap|Line Numbers
  1. package java_samples;
  2.  
  3. //import java.io.*;
  4.  
  5.  class class1{
  6.      static int part1 = 12;   // STATIC VARIABLE part1
  7.      static void member1(){    // STATIC METHOD member1; STATIC METHOD IS IMPORTANT  TO CALL part1
  8.  
  9.  
  10.         System.out.println("HELLO, THIS IS MEMBER1!!");
  11.         System.out.println(class1.part1); 
  12.     }
  13.  
  14.      static void member2(){
  15.  
  16.         class1.member1();
  17.     }
  18. }
  19.  
  20.  
But now, my question is: why can't I use the protected modifier on class1? class1 and samp1 belongs to the same package
Feb 5 '07 #10
r035198x
13,262 8TB
I have already tried some simple programs using static , and here is my sample codes, (these compile)...

Expand|Select|Wrap|Line Numbers
  1. //SAMPLE PROGRAM ON THE USE OF STATIC MODIFIER
  2.  
  3. package java_samples;
  4.  
  5. class samp1{
  6.  
  7.     public static void main(String args[]){
  8.         System.out.println(1+2+"3");
  9.         System.out.println("1"+ 2+1+2);
  10.         class1.member1();
  11.         class1.member2();
  12.         System.out.println(class1.part1); // part1 is static, it can be accessed even without creating an object.
  13.     }
  14. }
  15.  
  16.  
Expand|Select|Wrap|Line Numbers
  1. package java_samples;
  2.  
  3. //import java.io.*;
  4.  
  5. class class1{
  6.      static int part1 = 12; // STATIC VARIABLE part1
  7.      static void member1(){    // STATIC METHOD member1; STATIC METHOD IS IMPORTANT TO CALL part1
  8.  
  9.  
  10.         System.out.println("HELLO, THIS IS MEMBER1!!");
  11.         System.out.println(class1.part1); 
  12.     }
  13.  
  14.      static void member2(){
  15.  
  16.         class1.member1();
  17.     }
  18. }
  19.  
  20.  
But now, my question is: why can't I use the protected modifier on class1? class1 and samp1 belongs to the same package
Post the code that you want to try the protected modifier with. I'm not really getting your question.
Feb 5 '07 #11
mayfjf
14
Post the code that you want to try the protected modifier with. I'm not really getting your question.
I was just wondering before why cant I use the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. protected class class1{
  3. .
  4. .
  5. .
  6. }
  7.  
  8.  
but I guess I have now the answer. Is it because protected is a method/field modifier??
Feb 8 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Aphrael | last post by:
I would like a regular expression to do so: Base: <A HREF="somelink" maybesomthing="heretoo">linkface</A> and I want: (somelink) linkface Is this possible ? If yes, how ? And by the way, if...
4
by: Laurence Nuttall | last post by:
What is the modifiers property of a label mean? I looked in the help, but couldn't find any explantion for it. Thanks in Advance, Laurence Nuttall Programmer Analyst III
3
by: kchalla | last post by:
Can anybody let me know the difference between public and private class access modifiers? Thanks in advance
5
by: Ook | last post by:
Is there any kind of naming convention for accessor and modifiers? What I've been doing is something like this: // accessor int getSize(); // Modifier void setSize( int newsize); private:
2
by: Bob Weiner | last post by:
Is it possible to create a property and specify different access modifiers for the get and set methods? From the property definition it appears that you can define attributes but not access...
4
by: Picho | last post by:
Hi all, Using reflection, I can invoke/call private methods of an object. is this intended? if yes, why? in what scenario (example would be good) should I be givven the option to use...
6
mayfjf
by: mayfjf | last post by:
1.Hello, I wonder what are the differences between modifiers? Private, public, default, static...? I have reread and reread my java book, but I just can't understand.
13
by: Tom Baxter | last post by:
Hi everyone, Has anyone looked at section 18.1.1 of the C# spec? It indicates 'new' and 'protected' are valid modifiers on struct declarations. First, how can 'protected' be valid on a struct,...
2
by: devgupta01 | last post by:
I have seen the class with public and without modifiers and method with public, protected or private modifiers. I am confused how to decide modifiers for a class?
1
by: sumsin | last post by:
Is there any difference between 'qualifiers and modifiers? Or both are synonyms, because in general they are used interchangeably. Which is the standard word from language perspective? What are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.