Showing posts with label Inheritance in Java. Show all posts
Showing posts with label Inheritance in Java. Show all posts

99 Write a Java program to illustrate multilevel inheritance such that country is inherited from continent. State is inherited from country. Display the place, state, country and continent.

Code: import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; class Continent {   String con...
Read More

98 Create class student having method getdata() which should accept details of student such as rollno, name and marks of 3 subject. Extend class result from student. Define a method cal() in result to calculate the total and average of marks and display it.

Code: import java.util.Scanner; class Student { // Instance Variable int rollno,m1,m2,m3; String name;    void getdata() { ...
Read More

68 What is Co-Variant return type in Java?

Code 1 : class A { A m1() { return new A(); } } class B extends A { /* Valid A m1() { return new A(); } */ ...
Read More

72 How to Create Sub packages in Java?

Code: package com.atharva; public class Demo { public static void main( String args[] ) { System.out.println(" Sub Pac...
Read More

71 How to Create Program on Package in Current Location?

Code : package codingatharva; public class PackageDemo { public static void main( String args[] ) { System.out.println(...
Read More

70 Run time Polymorphism | Dynamic Binding | Late/Lazy Binding

Code : class A { void m1() { System.out.println("  super class m1() "); } } class B extends A { void m1() ...
Read More

69 Compile time polymorphism | Static polymorphism | Early Binding in Java

Code: class Test { static void m1() { System.out.println("  super class Test m1() "); } } class Demo extends Tes...
Read More

67 Method Overriding Rules for Exception in Java

Code: import java.io.*; class A { void m1() throws IOException { } } class B extends A { /* We Can write Same Class Ex...
Read More

66 Method Overriding in Java

Overriding toString() method. Code: package com.ca.atharva; class Student { int sid = 101; String sname = "ram"; ...
Read More

65 Program on Abstract Class, Interface and their Relations in Java ?

Code: interface I { public abstract void m1(); public abstract void m2(); } /* Relation: Interface to Interface */ interface J...
Read More

62 Program on How to Initialize the non-static / Instance Variable by using Constructor in Java

Code: //How to Initialize the non-static / Instance Variable by using Constructor import java.util.Scanner; class Account { long ...
Read More

61 Program on Multilevel inheritance in Java

Code: class A { int a = 111; static int b = 222; void m3() { System.out.println(" A-m3() "); } void m4() ...
Read More

59 Program on Single Level Inheritance in Java

Code: // Program on single level inheritance class A extends Object { } class Test { public static void main( String[] args ...
Read More