<?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>class/statice varibles | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/class-statice-varibles/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:33:46 +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>Java Variables -Part II</title>
		<link>https://studentprojects.in/software-development/java/java-variables-part-ii/</link>
					<comments>https://studentprojects.in/software-development/java/java-variables-part-ii/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Thu, 23 Feb 2023 07:28:41 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Variable]]></category>
		<category><![CDATA[class/statice varibles]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10200</guid>

					<description><![CDATA[<p>2. Instance Variables: An instance variable is a variable that is declared within a class, but not within a method or constructor. Unlike static variables, these variables are declared without the use of the &#8220;static&#8221; keyword. They can be accessed by any method or constructor within the class. Example: Output: 3. Class/Static Variables: A static</p>
<p>The post <a href="https://studentprojects.in/software-development/java/java-variables-part-ii/">Java Variables -Part II</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><strong>2. Instance Variables:</strong></p>



<p>An instance variable is a variable that is declared within a class, but not within a method or constructor. Unlike static variables, these variables are declared without the use of the &#8220;static&#8221; keyword. They can be accessed by any method or constructor within the class.</p>



<p>Example:</p>



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



<p>Output:</p>



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



<p><strong>3. Class/Static Variables</strong>:</p>



<p>A static variable is a variable declared within a class, but outside of any method or constructor. It is differentiated from an instance variable by its declaration using the &#8220;static&#8221; keyword. These variables can be accessed by all methods or constructors within the class.</p>



<p>Example:</p>



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



<p>Output:</p>



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



<p>Variables that are not declared static result in errors.</p>



<p>Example:</p>



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



<p>Output:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">Cannot make a static refrence to a non-static field</code></pre><p>The post <a href="https://studentprojects.in/software-development/java/java-variables-part-ii/">Java Variables -Part II</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/java/java-variables-part-ii/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
