209k views
2 votes
Which is the instance variable in the given code?

public class Person{

public intpid;

private double salary;

public Person (intpersonID){
pid = personID;
}

public void setSalary(double empSal){
salary = empSal;
}

public void printDetails(){
System.out.println("id : " + pid );
System.out.println("salary :" + salary);
}

public static void main(String args[]){
Person P = new Person("P1");
P.setSalary(100);
P.printDetails();
}
}


A. public intpid;
B. private double salary;
C. intpersonID
D. double empSal
E. Person P = new Person("P1");

Which is the instance variable in the given code? public class Person{ public intpid-example-1
User M G
by
4.7k points

1 Answer

3 votes

Answer:

Person P is a new instance of Persons class

-- located in the main class

User Ragnar Kruse
by
6.1k points