Computer Science, asked by saikrishna25052000, 12 days ago

class HackerEarth {
int val 10;
public static void main(String[] args) {
HackerEarth obj = new HackerEarth();
System.out.println(obj.val);
}
}​

Answers

Answered by poojadhole878
4

answer of given que is

10

Answered by MotiSani
0

Output: 10

  • We first create an object "obj" of class type HackerEarth, using the statement:

        HackerEarth obj = new HackerEarth();

  • An object is that entity in programming which stores its state in fields or variables and expresses its behavior through methods or functions.
  • The object obj has one state which we have declared using the variable name "val". The state val has been initialized to 10.
  • The value stored in the state val of the object obj is 10.
  • When we print the state val of the object obj i.e. System.out.println(obj.val);

        the value stored in val i.e., 10 is printed.

  • Hence the output of the given code snippet is 10.

#SPJ3

Similar questions