public class Myclass{ private static int count=0; private int x; //} public Myclass(int i) { x=i; } public void incrementCount(){ count++; } public void printX(){ System.out.println("Value of x : "+ x); } public static void printCount(){ System.out.println("Value of Count : "+count); } } public class MyclassDemo{ public static void main(String[] args){ Myclass myObject1 = new Myclass(5); Myclass myObject2 = new Myclass(7); } } what is the outputof the following java code? (Assume that following statements are written inside main) g) my Object1.setX(14); output: h) myObject1.incrementCount(); output: i) myObject1.printX(); output: j) myObject1.printCount(); output: k) myObject2.printCount(); output:
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:
public class Myclass{
private static int count=0;
private int x;
//}
public Myclass(int i)
{
x=i;
}
public void incrementCount(){
count++;
}
public void printX(){
System.out.println("Value of x : "+ x);
}
public static void printCount(){
System.out.println("Value of Count : "+count);
}
}
public class MyclassDemo{
public static void main(String[] args){
Myclass myObject1 = new Myclass(5);
Myclass myObject2 = new Myclass(7);
}
}
what is the outputof the following java code?
(Assume that following statements are written inside main)
g) my Object1.setX(14);
output:
h) myObject1.incrementCount();
output:
i) myObject1.printX();
output:
j) myObject1.printCount();
output:
k) myObject2.printCount();
output:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 6 images