What will be the output of the following code? [10] public class IdentifyMyParts { public static int x = 7; public int y = 3; public static void main(String[] args) { IdentifyMyParts a = new IdentifyMyParts(); IdentifyMyParts b = new IdentifyMyParts(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println(a.y); System.out.println(b.y); System.out.println(a.x); System.out.println(b.x); System.out.println(IdentifyMyParts.x); } }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
6. What will be the output of the following code? [10]
public class IdentifyMyParts {
public static int x = 7;
public int y = 3;
public static void main(String[] args) {
IdentifyMyParts a = new IdentifyMyParts();
IdentifyMyParts b = new IdentifyMyParts();
a.y = 5;
b.y = 6;
a.x = 1;
b.x = 2;
System.out.println(a.y);
System.out.println(b.y);
System.out.println(a.x);
System.out.println(b.x);
System.out.println(IdentifyMyParts.x);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images