You have the following code in a file called Test.javaclass Base{ public static void main(String[] args){ System.out.println("Hello"); }}public class Test extends Base{}What will happen if you try to compile and run this? Runtime error Compiles and runs with no output. Compiles and runs printing It will fail to compile. TRUE ANSWER : ? YOUR ANSWER : ?
Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class. native volatile static final abstract TRUE ANSWER : ? YOUR ANSWER : ?
What can directly access and change the value of the variable qusNo?package com.mypackage;public class Test{ private int qusNo = 100;} Any class that extends Test. None of these Only the Test class. Any class. Any class in com.mypackage package. TRUE ANSWER : ? YOUR ANSWER : ?
Which statements are most accurate regarding the following classes?class A{ private int i; protected int j;}class B extends A{ private int k; protected int m;} An object of B contains data fields k, m. An object of B contains data fields j, m. An object of B contains data fields j, k, m. An object of B contains data fields i, j, k, m. TRUE ANSWER : ? YOUR ANSWER : ?
What is the output for the below code ?public class A{ static{ System.out.println("static"); } { System.out.println("block"); } public A(){ System.out.println("A"); } public static void main(String[] args){ A a = new A(); }} None of these static block A static A A A block static TRUE ANSWER : ? YOUR ANSWER : ?
What is the result of compiling and running the following code?public class Tester{static int x = 4;public Tester(){System.out.print(this.x); // line 1Tester();}public static void Tester(){ // line 2System.out.print(this.x); // line 3}public static void main(String... args){ // line 4new Tester();}} Compile error at line 3 (static methods can't invoke this) Compile error at line 2 (constructors can't be static) 44 Compile error at line 1 (static x must be only accessed inside static methods) Compile error at line 4 (invalid argument type for method main ) TRUE ANSWER : ? YOUR ANSWER : ?
What will be the output after compiling and running following program code?public class Test{ static int a; public static void main(String[] args){ System.out.println("one"); call(1); } static void call(int a){ this.a=10; System.out.println("two "+a); }} Compile time error. one two 0 None of these one two 1 one two 10 TRUE ANSWER : ? YOUR ANSWER : ?
What will be the output for the below code?static public class Test{ public static void main(String[] args){ char c = 'a'; switch(c){ case 65 : System.out.println("one");break; case 'a': System.out.println("two");break; case 3 : System.out.println("three"); } }} Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted. one None of these Compile error - char can't be permitted in switch statement. two TRUE ANSWER : ? YOUR ANSWER : ?
The object is created with new keyword At run-time At Compile-time Depends on the code None of these TRUE ANSWER : ? YOUR ANSWER : ?
What is the result of compiling and running the following code?class Base{ private Base(){ System.out.print("Base"); }}public class test extends Base{ public test(){ System.out.print("Derived"); } public static void main(String[] args){ new test(); }} BaseDerived Derived Compilation Error Exception is thrown at runtime TRUE ANSWER : ? YOUR ANSWER : ?