answersLogoWhite

0


Best Answer

final is a keyword.it can be used for three posibilities.

they are

->we can assign the variable as final.

to declaring the variable as final to avoid the reusability of a variable.

now i display small program for this type.

class A

{

final int i=10;

a(int b)

{

i=b;

System.out.println(i);

}

}

public static void main(String args[])

{

A x=new A(20);

}

}

to execute this program .we have an error message.i.e.,the variable i can not be override.

->to use method have final keyword it can not be override.and also

->to use classes has final they can not be inhereted to sub classes.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

leela pandey

Lvl 2
4y ago

//We Declare an abstract class as-

abstract class Car

{

}

//Example of an abstract method

abstract void hondaCity(); //no method body and abstract

//Example of Abstract class that has an abstract method

abstract class Car

{

abstract void run();

}

class HondaCity extends Car

{

void run()

{

System.out.println("runs smartly");

}

public static void main(String args[])

{

Car obj = new HondaCity();

obj.run();

}

}

//OUTPUT will be-

runs smartly

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

You use the "abstract" keyword.

// Normal class
class A {}

// Abstract class
abstract class A{}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

public abstract class class_namne{

public abstract void method()

{}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When do you declare method or class final?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

When do you declare a method or class final?

if we declare a method as final then it can be changed.


What is the relationship between inheritance methods and the keyword final?

They are inversely related. That is: If you declare a method as final you cannot overridden in the child class If you declare a class as final you cannot inherit it in any other class.


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)


How can you create a class which cannot be inheritable?

Declare it final.


How do you prevent class extending in java?

Declare the class as final. final class A{ ... }


When do you declare a variable method and a class final?

When There is No Need to Change the Values of the Variables In Entire lifetime of That variables then we must use that Variable as Final Variable.


Can you declare main as final or not and why?

Yes you can. Try this: public class TestMain { /** * @param args */ public static final void main(String[] args) { System.out.println("Inside final mail method..."); } } It will print "Inside final mail method..." in the console.


Can you have a final abstract class?

No. The abstract keyword means that you cannot instantiate the class unless you extend it with a subclass. The final keyword means that you cannot create subclasses of that class.Combining them would lead to an unusable class, so the compiler will not let this happen.


When do you declare a class as final?

By using the final keyword in the class declaration statement. Ex: public final class Test {...}


How do you prevent extending a class in java?

You can declare a class as "final".


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


Discuss final method and final classes?

a method declared final can not be overridden, and a class declared as final can not be extended by its sub class.