Question : What is the proper way to defined a method that take two int values and returns their sum as an int value?
1. int sum(int first, int second) { first + second; } 2. int sum(int first, second) { return first + second; } 3. Access Mostly Uused Products by 50000+ Subscribers 4. int sum(int first, int second) { return first + second; }
5. void sum (int first, int second) { return first + second; }
Correct Answer : Get Lastest Questions and Answer : Explanation: Java - String trim() Method This method returns a copy of the string, with leading and trailing whitespace omitted.
Question : You have been given following code
public class SampleClass { public static void main(String[] args) { AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = new SampleClass(); sc = asc; System.out.println("sc: " + sc.getClass()); System.out.println("asc: " + asc.getClass()); } }
class AnotherSampleClass extends SampleClass { }
When you execute it, what will be printed ?
1. sc: class Object asc: class AnotherSampleClass 2. sc: class SampleClass asc: class AnotherSampleClass 3. Access Mostly Uused Products by 50000+ Subscribers 4. sc: class AnotherSampleClass asc: class AnotherSampleClass
2. public abstract class Toy{ public int caicuiatePrice (Toy t) ; void printToy (Toy t); } 3. Access Mostly Uused Products by 50000+ Subscribers public abstract class Toy{ public int caicuiatePrice (Toy t) ; public final void printToy (Toy t) {/*code goes here*/} }
4. public abstract class Toy{ public abstract int caicuiatePrice(Toy t){/*Code goes here*/} ; void printToy (Toy t){/*Code goes here*/}; }
1. Only the A.Java file compiles successfully. 2. Only the B.java file compiles successfully 3. Access Mostly Uused Products by 50000+ Subscribers 4. The A.Java and B.java files compile successfully 5. The B.java and C.java files compile successfully.
A. Requirements 1, 2, and 3 can be implemented by using the enhanced for loop. B. Requirements 1, 2, and 3 can be implemented by using the standard for loop. C. Requirements 2 and 3 CANNOT be implemented by using the standard for loop. D. Requirement 1 can be implemented by using the enhanced for loop. E. Requirement 3 CANNOT be implemented by using either the enhanced for loop or the standard for loop.