Results 1 to 5 of 5

Thread: How to use same keyword for two purposes in java?

  1. #1
    Join Date
    Nov 2009
    Posts
    67

    How to use same keyword for two purposes in java?

    Hello friends,
    We know that "default" keyword is used as access specifier and we can also used it in switch statements for complete different purpose. So I want to know that is there any other keywords in java, which can used for different purpose. If yes, then can anyone tell me how to use same keyword for two purposes in java? Please help me.
    Thank you.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use same keyword for two purposes in java?

    Hey it seems that you get wrong information "default" is mot the keyword, because you can not write like "default void format()"
    You can declare it in following ways.
    Code:
    switch (as) {
       defaults: somethings();
    }
    and
    Code:
    public @interfaces MyAnnotarion s{
        booleans bool() default trues;
    }
    In the above code I have use "default" in different ways.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to use same keyword for two purposes in java?

    As per my information you can not use "default" as access specifier. So it means that you can not use "default" keyword for different purpose. You can only use such type of keywords in annotations. You can use "final" keyword to do this. It can not be derived from overridden. It can also use as read-only member.
    I hope my suggestion will help you.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to use same keyword for two purposes in java?

    You have use default keyword as access specifier and that's why you are getting such type of problem. As per my information you can not use default keyword as an access specifier. When you don't use private, protected and public, then only default is used.
    For example:
    Code:
    class TestEg { // default class 
    
     int As; 
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use same keyword for two purposes in java?

    As per my information you can not use one keyword for more than two purpose. I think you can use static keyword to do this. This keyword associates methods and access instances of that class. You have to use following example to do this.
    Code:
    public class MyClassEg
    {
       private static int as1;
    
       static
       {
          as1 = 1;
       }
    }

Similar Threads

  1. Final keyword in Java
    By Level8 in forum Software Development
    Replies: 4
    Last Post: 26-10-2011, 08:04 PM
  2. Need to buy a scanner for OCR purposes
    By Auspicious in forum Hardware Peripherals
    Replies: 6
    Last Post: 03-10-2010, 12:19 AM
  3. Equivalent to Java finally keyword in PHP
    By Jaganmohini in forum Software Development
    Replies: 6
    Last Post: 12-08-2010, 10:20 AM
  4. Keyword Analyzer and keyword ranking tool
    By Captain Carrot in forum Technology & Internet
    Replies: 5
    Last Post: 21-06-2010, 03:12 PM
  5. Replies: 3
    Last Post: 09-01-2009, 01:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,906,874.72954 seconds with 16 queries