Can any one give an example (Source Code) on virtual
function implemetation in Java?



Can any one give an example (Source Code) on virtual function implemetation in Java?..

Answer / Neeraj Singh Vimal

Here's a simple example of virtual function implementation in Java using inheritance:nn```javanclass Base {n void printMessage() {n System.out.println("Hello from Base class");n }n}nnclass Derived extends Base {n @Overriden void printMessage() {n System.out.println("Hello from Derived class");n }n}nnpublic class VirtualFunctionExample {n public static void main(String[] args) {n Base ref = new Derived();n ref.printMessage(); // Output: Hello from Derived classn }n}```nIn this example, the printMessage() function is declared as virtual in the Base class and can be overridden by the Derived class.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Programming Languages AllOther Interview Questions

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells them, "You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another. "In the prison is a switch room, which contains two light switches labeled A and B, each of which can be in either the 'on' or the 'off' position. I am not telling you their present positions. The switches are not connected to anything. "After today, from time to time whenever I feel so inclined, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must move one, but only one of the switches. He can't move both but he can't move none either. Then he'll be led back to his cell. "No one else will enter the switch room until I lead the next prisoner there, and he'll be instructed to do the same thing. I'm going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back. "But, given enough time, everyone will eventually visit the switch room as many times as everyone else. At any time anyone of you may declare to me, 'We have all visited the switch room.' and be 100% sure. "If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will be fed to the alligators." What is the strategy they come up with so that they can be free?

6 Answers  


what is delimiter in sas ?

1 Answers  


how can i split string in a textbox in windows appication using C#.net

1 Answers   IBM,


In Bioinformatics, a DNA sequence is made up of a combination of 4 characters, namely “A,C,G,T”. A subsequence of a given sequence of characters a0, a1, …an- 1, is any subset of the characters taken in order, of the form ai0 , ai1 ,…..aik-1 where 0 &#8804; i0 <i1….< ik-1 &#8804; n-1. For example in the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, we can have subsequences “A,G,T”, “A,C,A,A” and many more. A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, has many palindromic subsequences, including “A,C,G,C,A” and “A,A,A,A” (on the other hand, the subsequence “A,C,T” is not palindromic). Devise an algorithm (using dynamic programming) that takes a sequence of characters X[0 … n-1] from the alphabet set (A,C,G,T) and returns the (length of the) longest palindromic subsequence. Implement the algorithm in an appropriate language.

1 Answers  


Hi, I'm doing B.com 3rd year. Simultaneously I'm doing software engineering in a private institution. I would like to know whether my B.com graduation alone is enough to get me a job in the IT field or should I do some PG course not MBA... suggest me...

1 Answers  


what is diff bet ref variable & instance of class

1 Answers  


Data structure used to impliment a menu:

0 Answers   Verifone,


I m new to the dbms. Recently i came across words clustered indexes & nonclustered indexes but i dont know what is this all about & whats the difference between them.. So please help me!!!!!!!!

1 Answers  


What sysoption determines where the macro facility searches a specific catalog for complied macro?

1 Answers   GE,


Difference between views and index in sas programming

1 Answers   Ventois,


hoe to data grid use in sql server 2000?

1 Answers   HCL,


cobol is execution r not without jcl

0 Answers   IBM,


Categories