Answers for "instance variable in java"

3

java variable declaration

java decleration

float simpleInterest; //Declaring float variable
Posted by: Guest on May-08-2020
0

How do you implement an instance variable in JAVA

package Edureka;
 
import java.util.Scanner;
 
public class Student
{
 
public String name;
 
private int marks;
 
public Student (String stuName) {
name = stuName;
}
public void setMarks(int stuMar) {
marks = stuMar;
}
 
// This method prints the student details.
public void printStu() {
System.out.println("Name: " + name );
System.out.println("Marks:" + marks);
}
 
public static void main(String args[]) {
Student StuOne = new Student("Ross");
Student StuTwo = new Student("Rachel");
Student StuThree = new Student("Phoebe");
 
StuOne.setMarks(98);
StuTwo.setMarks(89);
StuThree.setMarks(90);
 
StuOne.printStu();
StuTwo.printStu();
StuThree.printStu();
 
}
}
Posted by: Guest on August-17-2021
0

java variable declared

java decleartion 

int a, b, c;         // Declares three ints, a, b, and c.
int a = 10, b = 10;  // Example of initialization
byte B = 22;         // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a';        // the char variable a iis initialized with value 'a'
Posted by: Guest on May-08-2020
-2

instance variable java

A variable declared inside the class
  is called instance variable. Value of 
instance variable are instance specific.
public class InstanceVariableDemo
{
   // instance variable declared inside the class and outside the method
   int c;
   public void subtract()
   {
      int x = 100;
      int y = 50;
      c = x - y;
      System.out.println("Subtraction: " + c);
   }
   public void multiply()
   {
      int m = 10;
      int n = 5;
      c = m * n;
      System.out.println("Multiplication: " + c);
   }
   public static void main(String[] args)
   {
      InstanceVariableDemo obj = new InstanceVariableDemo();
      obj.subtract();
      obj.multiply();
   }
}
Posted by: Guest on January-22-2021

Code answers related to "instance variable in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language