Quiz
01-Objective-Wise-Constructors
Erstelle ein kostenloses Konto, um dieses Quiz zu beenden
Speichere deinen Fortschritt und sieh dir dein Endergebnis an.
oder mit deiner E-Mail registrieren
Schon ein Konto? Anmelden
Fragen in diesem Quiz (10)
1Which line contains a valid constructor in the following class definition?
public class TestClass{
int i, j ;
public TestClass getInstance( ) { return new TestClass( ) ; } //1
public void TestClass( int x, int y) { i = x; j = y; } //2
public TestClass TestClass( ) { return new TestClass( ) ; } //3
public ~TestClass( ) { } //4
}- ALine 1
- BLine 2
- CLine 3
- DLine 4
- ENone ofthe above.
2What will be the result ofattempting to compile the following program?
public class TestClass{
long l1;
public void TestClass( long pLong) { l1 = pLong ; } //( 1)
public static void main( String args[ ] ) {
TestClass a, b ;
a = new TestClass( ) ; //( 2)
b = new TestClass( 5) ; //( 3)
}
}- AA compilation error will be encountered at (1), since constructors should not
specify a return value. - BA compilation error will be encountered at (2), since the class does not have a
default constructor. - CA compilation error will be encountered at (3).
- DThe program will compile correctly.
- EIt will not compile because parameter type ofthe constructor is different than the
type ofvalue passed to it
- AA compilation error will be encountered at (1), since constructors should not
3Which ofthese statements are true?
- AAll classes must explicitly define a constructor.
- BA constructor can be declared private.
- CA constructor can declare a return value.
- DA constructor must initialize all the member variables ofa class.
- EA constructor can access the non-static members ofa class.
4Note: This question may be considered too advanced for this exam. Given:
class MySuper{
public MySuper( int i) { }
}a
bstract class MySub extends MySuper{
public MySub( int i) { super( i) ; }
public abstract void m1( ) ;
}c
lass MyTest{
public static void main( String[ ] args) {
MySub ms = new MySub( ) {
public void m1( ) { System. out. println( " In MySub. m1( ) " ) ; }
} ;
ms. m1( ) ;
}
}Wha
t will be the output when the above code is compiled and run?- AIt will not compile.
- BIt will throw an exception at run time.
- CIt will print In MySub. m1( )
- DIt will compile and run without any exception but will not print anything.
5Which ofthe following are true about the "default" constructor?
- AIt is provided by the compiler only ifthe class and any ofits super classes does not
define any constructor. - BIt takes no arguments
- CA default constructor is used to return a default value.
- DTo define a default constructor, you must use the default keyword.
- EIt is always public.
- AIt is provided by the compiler only ifthe class and any ofits super classes does not
6Which lines contain a valid constructor in the following code?
public class TestClass{
public TestClass( int a, int b) { } // 1
public void TestClass( int a) { } // 2
public TestClass( String s) ; // 3
private TestClass( String s, int a) { } //4
public TestClass( String s1, String s2) { } ; //5
}- ALine // 1
- BLine // 2
- CLine // 3
- DLine // 4
- ELine // 5
7Under what situations does a class get a default constructor?
- AAll classes in Java get a default constructor.
- B. You have to define at least one constructor to get the default constructor.
- CIfthe class does not define any constructors explicitly.
- DAll classes get default constructor from Object class.
- ENone ofthe above.
8You can call only public and protected constructors ofthe super class from a subclass
ifthe subclass is not in the same package because only those are inherited.- ATrue
- BFalse
9Given a class named Test, which ofthese would be valid definitions for the
constructors for the class?- ATest( Test b) { }
- BTest Test( ) { }
- Cprivate final Test( ) { }
- Dvoid Test( ) { }
- Epublic static void Test( String args[ ] ) { }
10Given the following code, which ofthese constructors can be added to class B without
causing a compile time error?
class A{
int i;
public A( int x) { this. i = x; }
}c
lass B extends A{
int j ;
public B( int x, int y) { super( x) ; this. j = y; }
}- AB( ) { }
- BB( int y ) { j = y; }
- CB( int y ) { super( y*2 ) ; j = y; }
- DB( int y ) { i = y; j = y*2; }
- EB( int z ) { this( z, z) ; }
Informationen
- Beschreibung
- OCA-SE-7 Objective-Wise-Ethuware-OCA-SE-7 Quiz am 01-Objective-Wise-Constructors, erstellt von Wong Fei Hung am 30/07/2017.
- Autor
- Wong Fei Hung
- Sprache
- Português
- Aufrufe
- 0
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz