Tag: programming languages

Questions Related to programming languages

Integer division by zero throws an exception.

  1. True

  2. False


Correct Option: A

package simplejava;public class TestConstructor{ int p ; public void TestConstructor(int p) { this.p=p; } public static void main(String[] args) { TestConstructor tp = new TestConstructor(10); TestConstructor tp = new TestConstructor(); System.out.println("p = "+tp.p); }}

  1. Compiler Error

  2. Exception

  3. p = 0

  4. p = 10


Correct Option: A

package simplejava; public class TestConstructor2 { int p; TestConstructor2() { System.out.print(" I am in Constructor"); } TestConstructor2(int p) { this(); this.p = p; System.out.print(" p = " + p); } public static void main(String[] args) { TestConstructor2 tp1 = new TestConstructor2(10); } }

  1. I am in Constructor p = 10

  2. I am in Constructor p = 0

  3. Compiler Error

  4. Exception


Correct Option: A

package simplejava;public class TestMain1 { TestMain1() { System.out.println("I am in Constructor"); } TestMain1(String message) { System.out.println("Message " + message); } public void main(String[] args) { TestMain1 nm = new TestMain1(); TestMain1 nm1 = new TestMain1("Hello"); }}

  1. Compiler Error

  2. Exception

  3. I am in Constructor

  4. Message Hello


Correct Option: B

A class can define two methods with the same name as long as the return types are different

  1. True

  2. False


Correct Option: B