Answer is D. obj2.c = -1
obj2.c will print -1 because the function setC in class only sets the variable C and getC returns c variable. while loop in Main class will not execute so obj2.setC will remain as it is that is -1.
Code Snippet with output given below :
//////////////////////////////////////////////////////////////////////
class Main
{
public static void main (String[] args) throws
java.lang.Exception
{
Q2 obj1 = new Q2();
Q2 obj2 = new Q2();
obj1.setA(0);
obj1.setB(0);obj1.setC(10);
obj2.setA(4);
obj2.setB(5);obj2.setC(-1);
while(!obj1.m2(1,3))
{
obj2.setC(obj2.getC() + 10);
}
System.out.println("obj2.c = " +
obj2.getC());
}
}
class Q2
{
private int a;
private int b;
private int c;
public void setA(int a){this.a = a;}
public void setB(int b){this.b = b;}
public void setC(int c){this.c = c;}
public int getA(){return a;}
public int getB(){return b;}
public int getC(){return c;}
public int m1(int a, int b){
return a+b;
}
public boolean m2 (int x, int y){
return m1(x, y) + x + y <
10;
}
}
//////////////////////////////////////////////////////////////////////

Given the following class: class Q2 { private int a; private int b; private int c;...
Modify the Triangle class (from previous code, will post under this) to throw an exception in the constructor and set routines if the triangle is not valid (i.e., does not satisfy the triangle inequality). Modify the main routine to prompt the user for the sides of the triangle and to catch the exception and re-prompt the user for valid triangle sides. In addition, for any valid triangle supply a method to compute and display the area of the triangle using...
can someone explain to me what does the dot mean ? and what would be the output and explain it? import java.io.*; public class Green { private int a; private int b; public Green(int aa,int bb) { a=aa; b=bb; } public void equals(Green c) { this.a=c.a;this.b=c.b;} public void fn(Green c) { this.a=3*c.b-c.a; this.b=2*c.a-this.b;} public void gg() { this.b=this.b-1; this.a=this.b-2; } public static void main(String args[]) { Green x=new Green(2,2); Green y=new Green(2,1); Green z=new Green(1,4); int xx=1,yy=2,zz=3; x.fn(y); z.gg(); System.out.println("...
Question 19 Given the following class: public class Swapper ( private int x; private String y public int z; public Swapper( int a, String b, int c) ( x-a; y b; zC; public String swap() ( int temp -x; x-z z temp; return y: public String tostring() ( if (x<z) return y: else return" +x+z What would the following code output? Swapper r new Suapper( 5, "no", 10); System.out.printin( r. swap ) ): no no510 510 e 15 Question 20...
the answer must be in java. thank you
Question 2 [8 points] Consider the class Class A below: class Class A implements Serializable{ int a; static int b; transient int c; String s; // Constructor public Class A (int a, int b, int c, Strings){ this.a = a; this.b = b; this.c = c; this.s = s; Complete the class Test to test the serialization and deserialization of the objects of class Class A. State the possible variable values following...
Define a class ArraySet using an array that represents a set and implements the ADT Set. Make the ArraySet resizeable. Then write a C++ program that adequately demonstrates your implementation. Hi, I wrote the program but I don"t know why it showing the output - 000 000 0 0 My main.cpp file code is this - #include<stdio.h> #include<iostream> #include<fstream> #include "ArraySet.h" #include "ArraySet.cpp" using namespace std; int main(){ ArraySet<int> setA, setB, setC; // adds to setA setA.add(10); setA.add(20); setA.add(30); //...
Java Inner class class Outer { private int x=10; private static int y=20 ; publics void M1( ) { int z=30; class Inner { public void M2() { Sytem.out.println(“sum: ”+ (x+y+z)); } } Inner i=new Inner(); i.M2() ; /// first call i.M2(); // second call i.M2(); // third call } // end of M1 publics static void main(String[] args) { Outer O = new...
1. Questions on inheritance. (a) Consider the following program segment: 1 class Array2 2 private: ClassX a: // ClassY b: // assume class ClassY is defined. assume class ClassX is defined . 3 4 5 public: 6 Array2 (int size) ( a new Clas sX [ size]; // a is an array of ClassX objects b new ClassY [size]: 1/ b is an array of ClassY objects 7 8 9 ) 10 ClassX getA() (return a; ) ClassY getB ()...
Given this code defining a class (shown with line numbers): 1: class newClass { 2: private: 3: int a; 4: public: 5: void setA(int value) { a = value; } 6: int getA() { return a; } 7: newClass(int value) : a(value) {}; 8: newClass() { a = 0; } 9: }; Which of the following snippets of code, when written in main() where the class above has been defined, will cause a syntax error when compiled? newClass something; something.setA(8);...
1) Using the Quadratic class you have already developed, make it Comparable. A Quadratic is bigger than another Quadratic if it opens faster. 2) Write a driver for Quadratic.java. In the driver program create a few objects and compare them . then create a list of those objects and sort them. import java.util.*; import java.lang.*; class Quadratic{ private double a,b,c; // Determines/declares the class variables to store the coefficients Quadratic(){ // Determine/declare the default constructor ...
Java question
Consider the following code segment. public class KaBoom { public int b; public void m1 () {//Your code goes here } public void m2 (KaBoom k) { System, out. print In (k. b); } } Complete the method body of m1 () indicated by the comment line. The m1 () method simply calls the m2 () method by passing in the current KaBoom object variable to m2 ().