51

Re: Virtual method + Exceptions in A C ++

52

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov;
Oh. All.
And in language Fortran you do not want to consider function about their virtuality in the given context?
Or we tell functions WinAPI...
Here functions WinAPI - they virtual or not?
And functions (procedure) FORTRAN?

53

Re: Virtual method + Exceptions in A C ++

MasterZiv wrote:

And functions in language Fortran

I do not climb there where I do not understand.
The initial statement has been made about virtuality of all functions in quite specific language.

54

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

it is passed...
I do not climb there where I do not understand.
The initial statement has been made about virtuality of all functions in quite specific language.

Well methods.

55

Re: Virtual method + Exceptions in A C ++

Yes-yes, to buttons of claims is not present.

56

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

In Java, not virtual is any method with modifiers private or final. Simply on determination.

Here, B:: test () - final, so not virtual (it is simple on determination)
Question: what will the program prints?

public class A {
void test ()
{
System.out.println ("A");
}
}
public class B extends A {
final void test ()
{
System.out.println ("B");
}
}
A a = new B ();
a.test ();

57

Re: Virtual method + Exceptions in A C ++

[spoiler.java]

class Test {
public static class Main
{
public static void main (String [] args)
{
A v;
v = new B (); v.msg ();
v = new A (); v.msg ();
}
}
static class A
{
static void msg () {System.out.println ("A class");}
}
static class B extends A
{
static void msg () {System.out.println ("B class");}
}
}

[/spoiler] [spoiler java Test$Main]

 A class
A class 

[/spoiler] From here morals: do not cause static methods through variables - (sooner or later) will be tangled in types.

58

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

static methods

And about final that?)))

59

Re: Virtual method + Exceptions in A C ++

[spoiler That absolutely without questions...]

class Test
{
public static class Main
{
public static void main (String [] args)
{
A v;
v = new B (); v.msg ();
v = new A (); v.msg ();
v = null;
System.out.println ("-");
A.msg ();
B.msg ();
}
}
static class A
{
static void msg () {System.out.println ("A class");}
}
static class B extends A
{
static void msg () {System.out.println ("B class");}
}
}

[/spoiler]

 java-cp bin Test$Main
A class
A class
--
A class
B class 

60

Re: Virtual method + Exceptions in A C ++

Anatoly Moskovsky wrote:

And about final that?)))

In sense?
The modifier final forbids concealment and redefinition, therefore in the conditions of an example there will be a compilation error.
With the modifier static (without final) - the ancestor and the descendant has different, but methods with the same name with identical signatures.

61

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

the Modifier final forbids concealment and redefinition, therefore in the conditions of an example there will be a compilation error.

There will be no error.

62

Re: Virtual method + Exceptions in A C ++

Anatoly Moskovsky wrote:

there will be no error.

 src\.java:19: error: msg () in B cannot override msg () in A
final static void msg () {System.out.println ("B class");}
^
overridden method is static, final
1 error 

[spoiler.java]

class Test
{
public static class Main
{
public static void main (String [] args)
{
A.msg ();
B.msg ();
}
}
static class A
{
final static void msg () {System.out.println ("A class");}
}
static class B extends A
{
final static void msg () {System.out.println ("B class");}
}
}

[/spoiler]

63

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov;
And it is possible all the same my example, instead of yours to check)))

64

Re: Virtual method + Exceptions in A C ++

Dimitry Sibiryakov wrote:

it is passed...
If in  Go the virtual methods and exceptions is intolerable brake... It
Google problem.

Most likely at them there speech not about brakes, and costs certain automatic  a course of performance of the code. They probably cannot define where will be transferred control by a call of the virtual functions and  .

65

Re: Virtual method + Exceptions in A C ++

Anatoly Moskovsky wrote:

And it is possible all the same my example, instead of yours to check)))

And that, forgive, to check in yours  an example: [spoiler javap-c Test]

 public class Test {
public Test ();
Code:
0: aload_0
1: invokespecial #1//Method java/lang/Object. "<init>" :() V
4: return
public static void main (java.lang. String []) throws java.io. IOException;
Code:
0: new #2//class B
3: dup
4: invokespecial #3//Method B. "<init>" :() V
7: astore_1
8: aload_1
9: invokevirtual #4//Method A.test:() V
12: return
}

[/spoiler]?

66

Re: Virtual method + Exceptions in A C ++

invokevirtual for a call final a method, which ostensibly not virtual.
Miracles))

67

Re: Virtual method + Exceptions in A C ++

Anatoly Moskovsky wrote:

invokevirtual for a call final a method, which ostensibly not virtual.
Miracles))

I am wrong in the relation final, but you illustrate my error an incorrect example.
From a byte-code which generates javac it is visible that the call becomes on the declared variable type, and the final method created by you - does not participate at all.
This the first.
The second.
That remains from virtuality in the course of execution - it is not known.
It already a little more other toolkit, but, as far as I understand, quite trivial for optimization and any  does not demand a situation.

68

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

From a byte-code which generates javac it is visible that the call becomes on the declared variable type, and the final method created by you - does not participate at all.

How does not participate? What does the program deduce?))

69

Re: Virtual method + Exceptions in A C ++

It is cut by censorship...
It is necessary to Sleep-walk: also I think badly and and any stupid errors I do.

70

Re: Virtual method + Exceptions in A C ++

[spoiler it is ready to the use without file application]

//Test.java
public class Test {
public static void main (String [] args) throws java.io. IOException
{
A v = new B ();
v.msg ();
}
}
class A
{
void msg () {System.out.println ("A class");}
}
class B extends A
{
@Override
final void msg () {System.out.println ("B class");}
}

[/spoiler]

71

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

[spoiler it is ready to the use without file application]

//Test.java
public class Test {
public static void main (String [] args) throws java.io. IOException
{
A v = new B ();
v.msg ();
}
}
class A
{
void msg () {System.out.println ("A class");}
}
class B extends A
{
@Override
final void msg () {System.out.println ("B class");}
}

[/spoiler]

Also what this proves?
What in java all nonstatic methods virtual?

72

Re: Virtual method + Exceptions in A C ++

semen.s.semen wrote:

That in java all nonstatic methods virtual?

In a byte-code for a final method becomes invokevirtual "in accordance with general practice".
That will be in the course of execution - it is necessary to look separately, but it is already more difficult.

73

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

it is passed...
In a byte-code for a final method becomes invokevirtual "in accordance with general practice".
That will be in the course of execution - it is necessary to look separately, but it is already more difficult.

Anyway it will be behavior of the virtual method

74

Re: Virtual method + Exceptions in A C ++

semen.s.semen wrote:

Anyway it will behavior of the virtual method

the execution Environment can and  and build in a call of a final method.
It is provided already in JLS.

75

Re: Virtual method + Exceptions in A C ++

Basil A. Sidorov wrote:

it is passed...
The execution environment can and  and build in a call of a final method.
It is provided already in JLS.

As there the environment of did not conduct - the method of the child will be caused