You are on page 1of 6
11:44AM © atl xX @ ClassMarker - Test Qh<: classmarker.com Question 1 of 12 Write the usage of final keyword in Java. Implement a simple program to understand Varargs. Final keyword is used to fixed the variables valu. Once a variable is declared as final, then the variable could not be changed. It is like a constan. For example: class basic{ final int x= 5; public void static main(String[] args){ basic obj = new basic(); obj.x = 10; System.out.printIn(obj.x); } } This program will generate an error, because we cannot assign a value to a final variable. In this integer value, it could not be changed in entire program. It is fixed in final keyword. Show word count Words: 86 Question 2 of 12 | a © < 12:29PM © al xX @ ClassMarker - Test Qh<: classmarker.com Time lett: 0:32:07 Question 7 of 12 A Implement a Java program where you have to make a class of name Student where there will be private member variables, a member function to give values in those variables, and another member function to print the values of those member variables. class Student{ private int id; private String name; void display(){ System.out.printin(id+" "‘name+);} public static void main(String[] args) { Student obj1 = new Student(); obj1.id = 101; obj1.name = “Ety*; obj1.display(); } Output: 101 Ety, Show word count Question 8 of 12 A . © < 12:29PM © atl xX @ ClassMarker - Test QA < classmarker.com Question 8 of 12 A Why do we need static keyword? Write the restrictions, if a method is declared as static. In java, static keyword is mainly used for memory management. It can be used with variable, methods and nested classes. It is a keyword which is used to share same variable or method of a given class. If we declared static keyword with any method, it is known as static method. *A static method can access static data member and can change the value of it. * A static method belongs to the class rather than the object of a clas. Show word count Question 9 of 12 A How to prevent Inheritance and overriding? There are three ways to prevent method overriding in java inheritanc. Final, static, and private methods can not be overriding by a subclas. If a method is declared final, static or private in base class, it cannot be overridden by the sub class. Sub class can not chnage the value of this base class. The value of the base class is like constant. When a class is declared as final than.no.other clase can.evtand it . @ < 10:52 AM © all x @ ClassMarker - Test Q « : classmarker.com . Question 9 of 12 How to prevent Inheritance and overriding? There are three ways to prevent method overriding in java inheritanc. Final, static, and private methods can not be overriding by a subclas. If a method is declared final, static or private in base class, it cannot be overridden by the sub class. Sub class can not chnage the value of this base class. The value of the base class is like constant. When a class is declared as final then no other class can extend it. Show word count ~ Question 10 of 12 What is Method Overriding? Why overridden methods? Method overriding: Method overriding happens if the sub class method is satisfied the following conditions with super class method:- * method name should be the same * the argument should be the same * return type also should be the same. The method overriding is useful. The benefit of overriding is that the sub class can provide some specific information about that sub class type than the super class. r © 4 10:41AM © al x @ ClassMarker - Test Q « : classmarker.com Bytecode: Bytecode is program code that has been compiled from source code into low-level code designed for software interprete. Java is a platform independent language that means it is a high level languag. It works on different platforms like Window, Mac, Linux, etc. Once a java program is create, it can be run on other platforms use the JVM(java virtual machin). A single program works on different platforms without any modificatio. So that's why java is a platform independentlanguag. Show word count ~ Question 12 of 12 Define Inheritance. Why do we need Inheritance? Inheritance: Inheritance means one class can extend to another class, So that, the codes can be reused from one class to another class. The existing class is known as Super class, and the derived class is known as a sub class. Inheritance is used for public and protected members only. Once we create a vode in Super class then inherit this code into another class. So, we can not write the same thing again. We can reused the Super class code into sub clas. Show word count ~ rs] © 4 11:36AM © @ @ x @ ClassMarker - Test Q « classmarker.com What is constructor overloading? Give an example of using object as parameters. Constructor Overloading: Constructor overloading in java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task number of parameter. For example: class student{ String name; int id; student(int i, String s){ id =i, name = s; } void display(){ System.out.printin(id+" "tname); } public static void main(String args[]){ student s1 = new student(101, "Riya’); student s2 = new student(102, "Afroja’); s1.display(Q; s2.display(Q); } } Output: 101 Riya 102 Afroja Show word count ~ ts] © 4

You might also like