package p1; public interface DoInterface { void method1(int n1); // line n1 }
package p3; import p1.DoInterface; public class DoClass implements DoInterface { public DoClass(int p1) { } public void method1(int p1) { } // line n2 private void method2(int p1) { } // line n3 }
public class Test { public static void main(String[] args) { DoInterface doi= new DoClass(100); // line n4 doi.method1(100); doi.method2(100); } } Which change will enable the code to compile?
1. Adding the public modifier to the declaration of method1 at line n1 2. Removing the public modifier from the definition of method1 at line n2 3. Access Mostly Uused Products by 50000+ Subscribers 4. Changing the line n4 DoClass doi = new DoClass ( );
Correct Answer : Get Lastest Questions and Answer : Private members (both fields and methods) are only accessible inside the class they are declared or inside inner classes. private keyword is one of four access modifier provided by Java and its a most restrictive among all four e.g. public, default(package), protected and private.
Correct Answer : Get Lastest Questions and Answer : Explanation: The Integer class value of 0 returns an Integer from given string. But we need to pass string which has correct format for integer otherwise it will throw a NumberFormatException. In this case we have passed string which is not an integer value (since what we passed is fractional number), so option D is correct.
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; }
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