Super Class
Super or parent class is a class which
properties are inherited by some other class. Object class is a super class,
which is inherited by all the class by default. Exists in java.lang package. To
inherit the properties of super class we need to use extends keyword like below:
class Lcd extends Television{
}
In real world, we can take example of
Television. The basic television has minimum a screen, remote, speaker etc.
There are so many types of televisions like LED, LCD, Smart, 3D etc. All are
these are television because they inherit the property of television.
Base Class
Sub or child class is a class which inherits
the properties of Super class. Like LED, LCD etc are child class of television
and television is super class of LED and LCD.
class Lcd extends Television{
}
String Class
String class is a mutable class. Which is use
to store any type of value or sequence of characters as String object. String
uses char array to store string values. Value of string always in between
inverted commas (“”).
class LCD extends Television{
String channelName = “MTV” ;
}
Now, we have learned all the basics of a java
program. Let’s develop a program.
class Television{
int numOfChannels = 10; //instance variable
String channelName = “Mtv”; //instance
variable
//Class method
public static void main(String[] args){
System.out.println(“Number of channels ”+
numOfChannels);
System.out.println(“Name of channels ”+
channelName);
}
}
No comments:
Post a Comment
Thank you for your comments.