Now, we will first write a program using a “has a relationship ” in Single Inheritance.
Step 1
Let’s open Notepad and enter the following code.
Code
class Test
{
void show()
{
System.out.println(“welcome in java method”);
}
}
class demo
{
public static void main(String arg[])
{
Test t=new Test();
t.show();
}
}
Step 2: Name it as “hasrel.java” and save the file in any location. i saved at “C:/kiran/program”.
step 3: open command prompt(press window +R and write cmd and hit ok).
step 4: Go to “command prompt.
step 5: Go to “C:/kiran/program” by using cmd.
Step 6: now, write the following code for cheking my java file is compile or not.
javac hasrel.java
My java file is compiled successfully.
Step 7: write the following code in command prompt. press enter and see the output.
java demo
//demo is a class name which is written in my “hasrel.java” file.
output
Now, we write the program by using “is a relationship ” in Single Inheritance.
Step 8: write the code in the notepad.
//code
class Test
{
void show()
{
System.out.println(“welcome in java method!!!”);
}
}
class demo extends Test
{
public static void main(String arg[])
{
demo d=new demo();
d.show();
}
}
Step 10: now, write the following code for cheking my java file is compile or not.
javac hasrel.java
My java file is compiled succesfully.
Step 11: Follow the step 7.
output
I hope you like this java file.
happy codding.