The Artima Developer Community
Sponsored Link

Java Buzz Forum
final static string vs string in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
final static string vs string in java Posted: Jul 19, 2015 2:34 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: final static string vs string in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

Static final variable java example:

  • If we declare any variable as static means it is class level variable.
  • If we declare any variable as static final its class level variable and its value can not be changed 
  • final static variables are constants in java.
  • We can access these final static variables directly without using object or class name.
  • We can not change the value of final static variables in any object.

    java example program on final static variable 

    1. Class A{
    2.  
    3. public static final String str="Learn Java Online";
    4.  
    5.  public static void main(String[]  args){ 

    6. System.out.println(str); 
    7.  //str="j2ee Interview Questions"; gives error

    8. }
    9. }

    Output:
    1. Learn Java Online

    Static String:

    • static Strings are class level strings.
    • we can access these static Strings using class name.


    1. Class A{
    2.  
    3. public static String str="Learn Java Online";
    4.  
    5.  public static void main(String[]  args){ 

    6. System.out.println(A.str); 
    7. System.out.println(str);
    8.  

    9. }
    10. }

    Output:
    1. Learn Java Online
    2. Learn Java Online

    Read: final static string vs string in java

    Topic: Apache Maven - Playlist Previous Topic   Next Topic Topic: Apache Server - Playlist

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use