Day 52 | Daily Java interview question | #ocjp #scjp

preview_player
Показать описание
Daily Java interview questions
core Java interview questions
Java interview questions
Java for beginners
Java guess output
learn Java
Java mock interview
Java mock interview questions
springboot
springboot questions
#scjp #javaprogramming #javainterviewquestion #javatutorial #learnjava #javaquestions #interview #javacertification
Рекомендации по теме
Комментарии
Автор

First of all parent can controlled Child class.

create a Parent class
Create static variables, and static non return method
With System.out.println("Parent");

Second create class Child extends with Parent class

Finally, public class Test is called Main class
Parent create method and variable static, so not create any Object directly call that method and variable,
That Child class call print()and num

Final output is :
Parent
100

ajin-pfdw
Автор

Yes first it checks in child class and that variables and methods are inherited from parent by extends key word then execution process starts
Output
Parent
100
That is the beauty of inheritance ❤️

crazycarrot
Автор

Parent
100
It's concept of inheritance

fizajakate
Автор

We can not access the non static class directly without creating object .

vengateshan
Автор

Firstly create child class object then we can access method of parent class

volleyballheaven
Автор

So here the function is called i.e. Child() so first parent will be printing and then 100.
So basically ans is
Parent
100

aaryamanbahale
Автор

Im a beginner.. if u can.. pls explain me bro

ranjithkumar-crdz
Автор

The child class inherits all the methods and variables from parent class. As the method and variable are static you can access them with parent or child class names directly without any object creation.
Parent.print()
Child.print()
Parent.num
Child.num

ashokkumar-vior
Автор

First of all we can not creat object of parent or child class.. so the it through error

Coder..
Автор

I have a doubt can we inherit static methods?

isuwjtg
Автор

The child inherits everything from the parents that isn’t specifically defined. Since the variables and functions are static think of them like the Math library. It’s
Parent
100

KingGisInDaHouse
Автор

I have a double to access the parent or child class we require to create a object to the child class iam i right or may i know the right answer with explanation

learnwitha.g
Автор

if num is non-static in Parent class we will get exception.
static with inheritance follow method/variable hiding
ans will be :
Parent
100

arekuti