Wednesday, January 28, 2015
Like the article?
Today we are going to learn Inheritance in JAVA. I've created four java class file. Those are:
1. fatherswealth.java ( Superclass )
2. lawyer.java ( Main Class )
3. myself.java ( Subclass )
4. mybrother.java ( Subclass )
Here are the codes:
1. fatherwealth.java
4. lawyer.java
1. fatherswealth.java ( Superclass )
2. lawyer.java ( Main Class )
3. myself.java ( Subclass )
4. mybrother.java ( Subclass )
Here are the codes:
1. fatherwealth.java
/*Inheritance means inheriting stuffs ( variables, methods etc ) from other class.
Why inheritance is important?
Well, if we need same stuffs for many classes. We need to write code in every class
rather doing that we will write same thing in one class and access that from other
class through inheritances.
*/
package myinheritence;
//my java super class
public class fatherswealth {
public static void fatherswealth() {
// TODO Auto-generated method stub
System.out.println("My car, flat, lands all are for my two sons!");
}
}
2. myself.java
package myinheritence;//my Java Sub class
public class myself extends fatherswealth{
/* in java writing Extends after class name means, you are inheriting.
* Here we are going to inherit everything from the fathers Wealth class.
*/
public void fromFather(String[] args) {
//System.out.println("my father says, ");
}
}
3. mybrother.java
package myinheritence;
/* This is my my java subclass.
Note: we will inherit a class by using the keyword EXTENDS
*/
public class mybrother extends fatherswealth{
// in this mybrother class we are also inheriting the class fatherswealth
public void fromFather(String[] args) {
System.out.println("printing from mybrother dot java class, My father says, ");
// calling by the power of inheritance
fatherswealth fb= new fatherswealth();
fb.fatherswealth();
// we can use super keyword to call also from super class
super.fatherswealth();
System.out.println("Ends printing frtom my brother dot java class");
}}
4. lawyer.java
package myinheritence;
public class lawyer {
public static void main( String[] args ) {
/*
Now i will create the object from the myself class to access the class.
as the class is inherited, i can access the fatherwealth class through mybrother class
*/
myself meObj = new myself();
mybrother myBro = new mybrother();
/* object and method name separated by dot for printing the outcomes which are
inherited from the fatherwealth class
*/
// calling inheritance for my brother.
myBro.fromFather(args);
myBro.fatherswealth();
// calling inheritance from me
meObj.fromFather(args);
meObj.fatherswealth();
/*
if you use the java Static keyword in method, you can access it without creating object.
i used static keyword in fatherswealth class, so i can call it without object like below example.
*/
fatherswealth.fatherswealth();
}
}
/* Note 1: only public methods can be inherited.
Note 2: If you want to keep one method as same as inherited class, you can write that in your subclass by overriding.
Note 3: If you inherit a superclass and that superclass inherits another class. then you will access your immediate superclass
and also the superclass that your superclass accessed.
Note 4: A static and final method can not be overridden.
Note 5: Method overloading deals with the notion of
having two or more methods(functions) in the same class with the same name but different arguments.
*/
RELATED POSTS
Subscribe to:
Post Comments (Atom)
Search
Powered by Blogger.
Contact with Rubel
Popular Articles
-
Hello mobile apps developers! if you are developing Mobile application in Phonegap platform. You might face a problem in sometime ' C...
-
Hello Google Play Android Developers! Recently, Google is forcing its developers to use Android Studio rather than using Android Developmen...
-
Hello developers! Hope you are doing well. Many people are coming to application developing, specially in the Android arena. Now, What! Th...
-
Polymorphism We are going to create four Java class in our Polymorphism class. Those are: 1. human.java class 2. women.java class...
-
Even if you are not from Computer Engineering background, still you can have Career in Mobile Application Development. Honestly speaking, b...
-
People related to programming and coding often make mistakes or misuse the words Coders and Programmers by not knowing properly. So, questi...
-
Today we are going to learn Inheritance in JAVA. I've created four java class file. Those are: 1. fatherswealth.java ( Superclass ) ...
Tags
- About Me
- admob
- advice
- Android
- Android Development
- android help
- Android SDK set Up
- Android Studio
- Apps development
- Artcell
- bluehost
- body building
- Can't you make your body building at home?
- Career
- career opportunities
- Coding
- coding problem
- computer science and engineering
- cse
- CSS
- css tricks
- Differences Between Programmers and Coders
- Do you really need to go at Gym?
- Do you really need to go to Gym for having a good shaped body?
- Education
- engineering
- Error
- experience sharing
- fitness center
- Free templates
- good life advice
- google adsense
- google adsense success
- google play
- google play account open
- gym
- hostgator
- How can I get a Google Adsense account
- How to be a freelance
- How to develop android application
- how to develop mobile application
- how to earn money online
- how to make money online
- how to monetize mobile application
- HTML
- HTML/CSS
- Java Tutorial
- Lifestyle
- Linux
- Linux Os
- making money online
- Mobile Application Development
- mosharrof rubel
- noakhali zilla school
- online earning tips
- online earning ways
- phonegap
- Phonegap problem
- Programming
- r cannot be resolved to a variable type
- rubel
- software engineering
- southeast university
- Templates
- Ubuntu
- Ubuntu Help
- web hosting buy
- web hosting reseller
- why computer science?
- wordpress theme
Techonlogy
Subscribe Here
Label
- About Me
- admob
- advice
- Android
- Android Development
- android help
- Android SDK set Up
- Android Studio
- Apps development
- Artcell
- bluehost
- body building
- Can't you make your body building at home?
- Career
- career opportunities
- Coding
- coding problem
- computer science and engineering
- cse
- CSS
- css tricks
- Differences Between Programmers and Coders
- Do you really need to go at Gym?
- Do you really need to go to Gym for having a good shaped body?
- Education
- engineering
- Error
- experience sharing
- fitness center
- Free templates
- good life advice
- google adsense
- google adsense success
- google play
- google play account open
- gym
- hostgator
- How can I get a Google Adsense account
- How to be a freelance
- How to develop android application
- how to develop mobile application
- how to earn money online
- how to make money online
- how to monetize mobile application
- HTML
- HTML/CSS
- Java Tutorial
- Lifestyle
- Linux
- Linux Os
- making money online
- Mobile Application Development
- mosharrof rubel
- noakhali zilla school
- online earning tips
- online earning ways
- phonegap
- Phonegap problem
- Programming
- r cannot be resolved to a variable type
- rubel
- software engineering
- southeast university
- Templates
- Ubuntu
- Ubuntu Help
- web hosting buy
- web hosting reseller
- why computer science?
- wordpress theme
Sponsor
Categories
- About Me
- admob
- advice
- Android
- Android Development
- android help
- Android SDK set Up
- Android Studio
- Apps development
- Artcell
- bluehost
- body building
- Can't you make your body building at home?
- Career
- career opportunities
- Coding
- coding problem
- computer science and engineering
- cse
- CSS
- css tricks
- Differences Between Programmers and Coders
- Do you really need to go at Gym?
- Do you really need to go to Gym for having a good shaped body?
- Education
- engineering
- Error
- experience sharing
- fitness center
- Free templates
- good life advice
- google adsense
- google adsense success
- google play
- google play account open
- gym
- hostgator
- How can I get a Google Adsense account
- How to be a freelance
- How to develop android application
- how to develop mobile application
- how to earn money online
- how to make money online
- how to monetize mobile application
- HTML
- HTML/CSS
- Java Tutorial
- Lifestyle
- Linux
- Linux Os
- making money online
- Mobile Application Development
- mosharrof rubel
- noakhali zilla school
- online earning tips
- online earning ways
- phonegap
- Phonegap problem
- Programming
- r cannot be resolved to a variable type
- rubel
- software engineering
- southeast university
- Templates
- Ubuntu
- Ubuntu Help
- web hosting buy
- web hosting reseller
- why computer science?
- wordpress theme
About
Social Share
Recent
Business
Video
Gallery
videos
Popular Posts
-
Hello mobile apps developers! if you are developing Mobile application in Phonegap platform. You might face a problem in sometime ' C...
-
Hello Google Play Android Developers! Recently, Google is forcing its developers to use Android Studio rather than using Android Developmen...
-
Even if you are not from Computer Engineering background, still you can have Career in Mobile Application Development. Honestly speaking, b...
-
You could find this topic little bit interesting and may not be hoping from me! Well, I was at gym for almost one year and I think I'm ...
-
Today, we are going to learn about Thread in JAVA. simpleThread.java Class public class simpleThread implements Runnable { /* ...
-
Polymorphism We are going to create four Java class in our Polymorphism class. Those are: 1. human.java class 2. women.java class...
-
Array: An array is something more or less like a container of data. Array container contains same type of data. Read More from Orac...
-
People related to programming and coding often make mistakes or misuse the words Coders and Programmers by not knowing properly. So, questi...
-
Today we are going to learn Inheritance in JAVA. I've created four java class file. Those are: 1. fatherswealth.java ( Superclass ) ...
-
Hello developers! Hope you are doing well. Many people are coming to application developing, specially in the Android arena. Now, What! Th...
Chiefs vs Falcons
ReplyDeleteChiefs vs Falcons live
nfl game pass
nfl live
live nfl
live nfl on cbs
Lions vs Saints
Lions vs Saints live
nfl game pass
nfl live
live nfl
live nfl on cbs
Rams vs Patriots
Rams vs Patriots live
nfl game pass
nfl live
live nfl
live nfl on cbs
Broncos vs jaguars
Broncos vs jaguars live
nfl game pass
nfl live
live nfl
live nfl on cbs
Texans vs Packers
Texans vs Packers live
nfl game pass
nfl live
live nfl
live nfl on cbs
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeletemicrosoft azure training in bangalore
rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in bangalore
This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
ReplyDeleteBest Devops Training in pune
Devops Training in Bangalore
Power bi training in Chennai