Thursday, 5 April 2012

Concrete Class

Function or Method
1   2  3
RT FN (PL)
{
//Body 4
}
-items 1,2,3 are called function header
-items 2,3 are know as function signature
-the function header is also know as declaration when written in an abstract class or interface
-items 1,2,3,4 are known as function definition
===
Important concepts:
Function Declaration
Function Definition
===
Concrete Class:
What:
A class that in which all methods are fully defined.
e.g.
class A{}
A is a class which has no methods in it but still it is a concrete class. It seems to be a useless class.
class B{
  private int x;
  public int getx(){ return x; };
  public void setx(int t){ x=t; }
  public String toString(){  return "" + x;  }
}
B is a concrete class also.
class C extends A{
  private int x;
  public int getx(){ return x; };
  public void setx(int t){ x=t; }
  public String toString(){  return "" + x;  }
}
C is also a concrete class inherited from A
===
Abstract Class:
What
It is an incomplete class i.e. it has some incomplete functionality
How:
by using the keyword abstract before class name
or declaring an abstract method in a class
or by inheriting a class from an abstract class
e.g.
abstract class P{
  public void dummy(){};
}
abstract class Q extends P{
 public abstract void test();
 public void full(){}
}
class R extends Q{
  public void full(){}
}
class T extends R{
  public void test(){}
}
class S extends P{}
the P class is abstract;
the Q class contains an abstract method
the R class is also abstract because it inherits an abstract method but does not override it
the T class is concrete because it properly overrides the test method from R

No comments:

Post a Comment