java variable declaration
java decleration
float simpleInterest; //Declaring float variable
java variable declaration
java decleration
float simpleInterest; //Declaring float variable
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();
}
}
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'
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();
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us