Convert the member function to static member function
class MyClass {
int x ;
public:
void set(int x) {
this->x = x ;
}
}
2) Convert the member function into non-inline function.
class Basketball {
int home ;
int visitor ;
public:
void setHome(int score) {
home = score;
}
void setVistor(int score) {
vistor = score ; }
} ;
1)
// Screenshot of the code
// code to copy
class MyClass {
static int x ;
public:
void static set(int x)
{
x = x ;
}
};
2)
// Screenshot of the code
// code to copy
void Basketball::setHome(int score)
{
home = score;
}
void Basketball::setVisitor(int score)
{
visitor = score ;
}
class Basketball {
public:
int home;
int visitor ;
void setHome(int x);
void setVisitor(int x);
} ;
Convert the member function to static member function class MyClass { int x ; public: void...
Explain in detail what the code below does: public class MyClass { public static void main(String args[]) { System.out.println(isUniqueChars("something")); } public static boolean isUniqueChars(String str) { int checker = 0; for (int i = 0; i < str.length(); ++i) { int val = str.charAt(i) - 'a'; if ((checker & (1 << val)) > 0) return false; checker |= (1 << val); } return true;...
What is the missing keyword in the program below? public class Batman { public static int minFunction(int n1, int n2) { int min; if (n1 > n2) min = n2; else min = n1; return min; //This is the value that will be returned from the minFunction method. //The value after the keyword return must match the return type from the method header. Ours is OK because they are both int. } // end the public method named minFunction }...
Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } t is non-static and it cannot be referenced in a static context in the main method. The program compiles and runs fine. The variable t is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.
Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } The variable t is private and therefore cannot be accessed in the main method. The program compiles and runs fine. t is non-static and it cannot be referenced in a static context in the main method. The variablet is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.
In the following program: public class Problem2{ public static int sample(int x, int y){ int z; ...... } public static void main(String[] args) { int a, b; ...... sample(a,b); } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...
c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s int z Myclass(int y) { z = y } } fill in the blanks (labelled i., ii. and iii.) in the definition of the method main, of the class StringProcessing, with i. a declaration of a variable named obj of type MyClass, initialised with a MyClass object so that its instance variable z has a value of 20, ii. an assignment of the instance...
ndicate the correct answers bases on the following code: public class IdentifyMyParts { public static final int X = 7; public int y ; public void display(){.......} } public static void main(){string [] args){ IdentifyMyParts Obj1; Obj1.X=8; Obj1.y=20; } a. IdentifyMyParts is a class b. X is a instance method c. y is an instance variable d. Obj1.X=100; e. Obj1.y=200; f. display() is a member function
Convert into pseudo-code for below code =============================== class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); ScoresCircularDoubleLL score=new ScoresCircularDoubleLL(); while(true) { System.out.println("1--->Enter a number\n-1--->exit"); System.out.print("Enter your choice:"); int choice=s.nextInt(); if(choice!=-1) { System.out.print("Enter the score:"); int number=s.nextInt(); GameEntry entry=new GameEntry(number); ...
package array; public class Test { static int[] data = (0,1,2,3,4,5,6,7,8); public static void main (String[] a) { for ( int i = 0;i<data.length; i++) { if(i %3 == 0) { System.out.print("A"); System.out.print(data[i]); System.out.print(" "); } } I need an explanation of what this code is doing ? is there anything wrong with it }}