Constructors, Classes, and Inheritance

Constructors, Classes, and Inheritance

9 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following statements is false regarding inheritence?

  1. A class can extend another class.
  2. A class can implement multiple interfaces.
  3. A class can extend multiple classes.
  4. An interface can extend another interface.
  5. A class can extend another class and implement an interface at the same time.
Question 2 Multiple Choice (Single Answer)

Which of the following is the Super class of all the classes in Java?

  1. Class
  2. Throwable
  3. Object
  4. String
  5. Super
Question 3 Multiple Choice (Single Answer)

How many parameterized constructors are defined for a Scanner class?

  1. 5
  2. 6
  3. 7
  4. 8
Question 4 Multiple Choice (Single Answer)

Which of the following statements is not correct about a constructor?

  1. A constructor can be executed simultaneously with the creation of an object.
  2. A constructor which is used for one object cannot be used again unless a second object is created.
  3. A constructor does not return a value.
  4. A constructor cannot be overloaded.
  5. A constructor must have the same name as its class.
Question 5 Multiple Choice (Single Answer)

What will be the output of java MyClass,java?
class Base
{
public static void main(String[] args)
{
System.out.println(In Base Class );
}
}
public class MyClass extends Base
{
}

  1. compile time error
  2. run time error
  3. execute successfully with no output
  4. prints In Base Class
  5. none of these
Question 6 Multiple Choice (Single Answer)

Find the output of the following program code.
class parent
{
final int a=10;
void meth()
{
System.out.println(parent);
}
}
class Test1 extends parent
{ int a=20;
public static void main(String[] args)
{
parent par = new parent(); parent par2 = new Test1(); par.meth(); par2.meth(); System.out.println(par.a); System.out.println(par2.a); } void meth() { System.out.println(child);
}
}

  1. parentchild1010
  2. parentchild 2020
  3. child child2020
  4. parentparent 2020
  5. childchild1010
Question 7 Multiple Choice (Single Answer)

Consider the following program code.
class person
{
private string name;
private int age;
void person()
{
name=Raju;
}
talk()
{
System.out.println(Hello I am + name);
}
}
Which constructor has been wrongly defined?

  1. class person()
  2. talk()
  3. person()
  4. private int age;
  5. none of these
Question 8 Multiple Choice (Single Answer)

The constructor StringBuffer() of a StringBuffer class creates a string buffer with the capacity of ________ characters by default.

  1. 8
  2. 16
  3. 32
  4. 64
Question 9 Multiple Choice (Single Answer)

Which of the following are constructors for the wrapper Byte class?


  1. ||
    |---|
    | Byte(Byte b1);
    Byte(String str1);|

  2. ||
    |---|
    | Byte(int b1);
    Byte(String str1);|

  3. ||
    |---|
    | Byte(byte b1);
    Byte(String str1); |

  4. ||
    |---|
    | Byte(byte b1);
    Byte(string str1);|