Загрузка...

USE OF FINAL KEYWORD WITH CLASS IN JAVA in Hindi Lecture 73

//Java final Class

A class declared with final keyword is known as final class.The final class cannot be inherited.
Syntax-----
final class student
{
//statement
}

Example----
final class student
{
public void show1()
{
System.out.println("parent class method");
}
}
//we cannot inherit the final class
class person extends student
{
public void show2()
{
System.out.println("child class method");
}
}
class example
{
public static void main(String args[])
{
person obj=new person();
obj.show1();
obj.show2();
}
}
When we compile the above code it shows a compile time error as the final class cannot be inherited.

//Java Keyword:Java final class
//show error as final class cannot be inherited

final class student
{
public void show1()
{
System.out.println("parent class method");
}
}
class person extends student
{
public void show2()
{
System.out.println("child class method");
}
}
class example
{
public static void main(String args[])
{
person obj=new person();
obj.show1();
obj.show2();
}
}

Видео USE OF FINAL KEYWORD WITH CLASS IN JAVA in Hindi Lecture 73 канала Learning Language
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять