OBJECT CREATION IN JAVA.
In the following example we have classes a and b. b extends a. In other words a is
the super class and b is the subclass. The following program shows FOUR
possibilities of creating objects of the classes a and b and the accessibility of the
objects.
package exercise;
public class Exercise {
public static void main(String[] args) {
a ob1=new a();
b ob2=new b();
a ob3=new b();
// a ob4=new b(); NOT ALLOWED
run:
ob1.f();
[Link]();
f In class A
fa In class A
ob2.f();
[Link]();
[Link]();
f In class B
fa In class A
fb In class B
ob3.f();
[Link]();
//[Link]();
f In class B
fa In class A
NOT ALLOWED
(total time: 0 seconds)
}
package exercise;
package exercise;
public class a {
void fa()
{
[Link]("fa In class
A");
}
public class b extends a{
void fb()
{
[Link]("fb In class B");
}
void f()
{
[Link]("f In class
A");
}
}
void f()
{
[Link]("f In class B");
}
}