Key words in Java | ||||
---|---|---|---|---|
abstract | assert | boolean | break | byte |
case | catch | char | class | const |
continue | default | do | double | else |
enum | extends | final | finally | float |
for | goto | if | implements | import |
instanceof | int | inter | long | native |
new | package | private | protected | public |
return | short | static | strictfp | super |
switch | synchronized | this | throw | throws |
transient | try | void | volatile | while |
public class Demo2
{
String name = "Fresherslead";
int age = 3;
System.out.println(name+" age is "+age);
}
Output : Fresherslead age is 3
In the above program we use int and String keywords, As these two are data types in java. In this simple example we store Fresherslead in the variable name as String datatype and 3 in the variable as int datatype.
class Student
{
void display()
{
System.out.println("Display method inside student class");
}
}
public class Keywords1
{
public static void main(String[] args)
{
Student st = new Student();
st.display();
}
}
Output : Display method inside student class
In this example we created object for the class Student to access the display() method. public, class,void, static, new keywords are used. Dont worry you will learn more about object, and object creationsin java in the upcoming tutorials.