Constructors, Classes, and Inheritance
Constructors, Classes, and Inheritance
Questions
Which of the following statements is false regarding inheritence?
- A class can extend another class.
- A class can implement multiple interfaces.
- A class can extend multiple classes.
- An interface can extend another interface.
- A class can extend another class and implement an interface at the same time.
Which of the following is the Super class of all the classes in Java?
- Class
- Throwable
- Object
- String
- Super
How many parameterized constructors are defined for a Scanner class?
- 5
- 6
- 7
- 8
Which of the following statements is not correct about a constructor?
- A constructor can be executed simultaneously with the creation of an object.
- A constructor which is used for one object cannot be used again unless a second object is created.
- A constructor does not return a value.
- A constructor cannot be overloaded.
- A constructor must have the same name as its class.
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
{
}
- compile time error
- run time error
- execute successfully with no output
- prints In Base Class
- none of these
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);
}
}
- parentchild1010
- parentchild 2020
- child child2020
- parentparent 2020
- childchild1010
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?
- class person()
- talk()
- person()
- private int age;
- none of these
The constructor StringBuffer() of a StringBuffer class creates a string buffer with the capacity of ________ characters by default.
- 8
- 16
- 32
- 64
Which of the following are constructors for the wrapper Byte class?
-
||
|---|
| Byte(Byte b1);
Byte(String str1);| -
||
|---|
| Byte(int b1);
Byte(String str1);| -
||
|---|
| Byte(byte b1);
Byte(String str1); | -
||
|---|
| Byte(byte b1);
Byte(string str1);|