<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Variables in java | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/variables-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Thu, 16 Feb 2023 07:28:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Variables in Java-Part I</title>
		<link>https://studentprojects.in/software-development/java/variables-in-java-part-i/</link>
					<comments>https://studentprojects.in/software-development/java/variables-in-java-part-i/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Wed, 22 Feb 2023 07:24:44 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[local variable]]></category>
		<category><![CDATA[Variables in java]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10198</guid>

					<description><![CDATA[<p>Information can be stored in variables, which the programmer can then change and refer to later in the code. The data type of a Java variable can provide information about the size and organisation of the variable&#8217;s memory. Syntax: There are three types of variables in java: A variable declared within the body of a</p>
<p>The post <a href="https://studentprojects.in/software-development/java/variables-in-java-part-i/">Variables in Java-Part I</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Information can be stored in variables, which the programmer can then change and refer to later in the code. The data type of a Java variable can provide information about the size and organisation of the variable&#8217;s memory.</p>



<p>Syntax:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">datatype variable = value</code></pre>



<p>There are three types of variables in java:</p>



<ol>
<li>Local variable</li>



<li>Instance variable</li>



<li>Class/Static variable</li>
</ol>



<ol type="A">
<li><strong>Local Variables:</strong></li>
</ol>



<p>A variable declared within the body of a method or constructor is referred to as a local variable. This is because the scope of a local variable is limited to the method or constructor in which it is defined, and it cannot be accessed by other methods in the class.To declare a local variable within the method body, the &#8220;static&#8221; keyword is used.</p>



<p>For example:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">public class variableType {
    public void localVariable() {
        String name = "Ben";
        int marks = 95;
        System.out.println(name + " Scored " + marks + "%.");
    }

    public static void main(String[] args) {
        variableType vt = new variableType();
        vt.localVariable();
    }
}</code></pre>



<p>Output:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">Ben Scored 95%.</code></pre>



<p>If an attempt is made to access a local variable outside the method or constructor in which it was created, it will result in an error.</p>



<p>For example:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">public class variableType {
    public void localVariable() {
        String name = "Ben";
        int marks = 95;
    }
    public void notLocalVariable() {
        System.out.println(name + " Scored " + marks + "%.");
    }

    public static void main(String[] args) {
        variableType vt = new variableType();
        vt.notLocalVariable();
    }
}</code></pre>



<p>Output:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">name cannot be resolved to a variable
marks cannot be resolved to a variable</code></pre><p>The post <a href="https://studentprojects.in/software-development/java/variables-in-java-part-i/">Variables in Java-Part I</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/java/variables-in-java-part-i/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
