/*Create a base class with an abstract print( ) method that is overridden in a derived class.
The overridden version of the method prints the value of an int variable defined in the
derived class. At the point of definition of this variable, give it a nonzero value.
In the base-class constructor, call this method. In main( ), create an object of the derived
type, and then call its print( ) method. Explain the results. */
abstract class print
{
abstract void print();
}
class p extends print
{
int p=10;
void print()
{
System.out.println("value of p is "+p);
}
}
public class a2q2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
p p2 = new p();
p2.print();
}
}

The overridden version of the method prints the value of an int variable defined in the
derived class. At the point of definition of this variable, give it a nonzero value.
In the base-class constructor, call this method. In main( ), create an object of the derived
type, and then call its print( ) method. Explain the results. */
abstract class print
{
abstract void print();
}
class p extends print
{
int p=10;
void print()
{
System.out.println("value of p is "+p);
}
}
public class a2q2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
p p2 = new p();
p2.print();
}
}

INHERITANCE ABSTRACT CLASS
Reviewed by sg
on
February 14, 2016
Rating:

No comments:
Post a Comment