Sep 10

Can a as protected declared method overwriten in an sub-class?

Antwort/ answer
Tagged with:
Aug 22

What is the Output of the following Code?

class Angestellter{

public String getName(){ return(“Angestellter”);}

public static void main(String args[]) {

Angestellter a = new Buchhalter ();

System.out.println(a.getName());

}

}

class Buchhalter extends Angestellter{

public String getName(){ return(“Buchhalter”);}

}



Antwort/ answer

Tagged with:
Aug 20

What is the output of the following Code?

class Angestellter{

public static void main(String args[]) {

Angestellter a = new Buchhalter ();

System.out.println(a.getName());

}

}

class Buchhalter extends Angestellter{

public String getName(){ return(“Buchhalter”);}

}

V79JBRKCR328

Antwort/ answer
Tagged with:
Aug 18

What is the output of the following code?

interface PersNr{ void setPersNr (short PersNr); }

public class Angestellter implements PersNr {

void setPersNr(short PersNr){ System.out.println(“short”);}
void setPersNr(long PersNr){ System.out.println(“long”);}

static public void main(String[] Args){

Angestellter a = new Angestellter();
a.setPersNr(1);

}

}

Antwort/ answer
Tagged with:
Aug 16

As explained a few days before, the return-type is not allowed to be changed at overwriting with one exception: covarian return types. Today I would like to explain what this means:

Let’s take an example:

class Angestellter {

void get_info () { … }

}

class Buchhalter extends Angestellter{

String get_info () { … } // Compiler-Error: return-value not compatible

}

Here, overwriting is not possible. In my next example things look different:

class Angestellter{

Angestellter get_info () { … }

}

class Buchhalter extends Angestellter {

Buchhalter get_info () { … } // covariant return-type, legal from java 1.5

}

This means, as long as it is derivated from an upper class, it is a covariant return type and therefore allowed.


Tagged with:
Aug 14

Which methods could be at … inserted and compiled without any error?

class Angestellter
{

void doSomething(String args) {}

}

class Buchhalter extends Angestellter
{

// put your code here

}

Methods:
void doSomething(int x) {}
String doSomething (String args){}
private void doSomething (String args) {}
protected void doSomething (String args) throws IndexOutOfBoundsException {}

Antwort/ answer
Tagged with:
Aug 08

In addition to the usual explanations an overview for the differences since it is quite important for SCJP-certification beeing able to distinguish between them.

overloading overwriting
arguments have to change not allowed to change
return-type can be changed not allowed to change. Only exception: covariant types
exceptions can be changed Can be less restrictive or fully removed. Not allowed to be more restrictive.
access-modifier can be changed not allowed to be less restrictive (e.g. not private instead of protected)
invocation will be determined at compile-time will be determined at runtime
example: showLeaves() showLeaves(int x) showLeaves()
Tagged with:
preload preload preload
http://www.wikio.de Blog Top Liste - by TopBlogs.de Blogverzeichnis - Blog Verzeichnis bloggerei.de Bloggeramt.de Software
Webbhotell Top Blogs