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 |
Answer:
The correct answers are A, C and F
Explanation:
IdentifyMyParts is the name of a class which has a static variable named X and instance variable named y.
Also it has an instance method named display()
So, option B is wrong as it X is an instance variable, not instance method.
Option d and e are wrong as the values of X and y are 8 and 20, not 100 and 200.
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!
ndicate the correct answers bases on the following code: public class IdentifyMyParts { public static final...
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.
What is the output of the following code? Explain your answer. public class Test {public static void main (String [] args) {System.out. print((int) 5.6); System.out.println((int) 5.2);}}
please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...
What is wrong the following code? Explain. public class Test { public static void main(String[] args) { A a = new A(5.0); } class A { int value = 2; } }
What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);
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?
Consider the following Java 8 code, and select true statements: public interface Functionlnterface1 void abstFun1 (int x) public interface Functioninterface2( void abstFun2(int x); public class Main implements Functioninterface2( @Override public void abstFun2(int x) System.out.printin(3'x); public static void main(Stringl args) ( Functioninterface1 fobj (int x)->System.out.printin(2"x) fobj.abstFun1(5); Main me - new Main; me.abstFun2(5); Functioninterface2 fobj2-(int x)->System.out.printin(4%; fobj2.abstFun2(5) 2 in main will not run because abstFun2 was previoudly implemented. O The fobj instance of Functionlnterface1 is created using the lambda at runtime without...
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 will the code shown below print to the console? public class Cascade public static void print(int arg){ for(int i=0; i<arg; i++){ System.out.print(""); } System.out.println(""); if(arg > 1){ print(arg-1); } } public static void main(String[] args) { print(4); } } E B IV AA- IES XX, SE V GT 12pt Paragraph -