Professional Documents
Culture Documents
Marks : 15
class Parent {
int num = 100;
public void show() {
System.out.println(" I am parent");
}}
class AB {
int rollNo;
String name;
package com.tests.test3;
class C {
int id;
String name;
C(int id) {
this.id = id;
}}
class D extends C {
String color;
String type;
D() {
this.color = "Red"; }
D(String color) {
this();
this.color = color;
} }
package pack2;
import pack1.Parent;
public class B extends Parent{
public int foo() {
int i = 10 ;
return(this.num + i); }
6. State true or false. (0.25 marks will be cut for wrong answer) [3M]
a. Abstract class must have at least one abstract method.
b. Instance variables can not be accessed in static methods.
c. Overloading is example of runtime polymorphism.
d. We can override abstract methods.
e. We can override static methods.
f. Protected variables are not accessible to classes in same package if that class does not
extend.
7. Create a java class Cricketer. Class has int playerid, String name , Boolean isBaller , float
strikerate , int runs. All fields are private. Write getter setter for all fields of this class.
8. Write a main method in which you accept values from user to create 3 objects of cricketer
and display them. To display method you should use tostring method.
9. Create class Fish { String name , int gills } . Class Fish has method void swim() which has
some default implementation. Create two subclasses of Fish , GoldFish and Whale. Override
swim method in GoldFish by changing access modifier and Override in Whale class by
changing its return type.
10. Write a program to accept a number from user and generate following series till that
number. 1, 2 , 1 , 3 , 2 , 5 , 3, 8 , 5, 13 , 8 , 21,
13. What is significance of final keyword for variable, method and class.